How To Automatically Empty WordPress Trash Using Days Parameter?

empty wordpress trash

When you delete any blog post then it goes to the trash section. You can empty WordPress trash manually by clicking on the “delete permanently” option.

But what would you do to set the number of days to keep the post in the trash folder? How would you set the maximum number of days for the WordPress trash to get emptied?

In this tutorial, I am going to provide you the code which can help you to automatically empty WordPress trash.

Use EMPTY_TRASH_DAYS To Empty WordPress Trash.

In WordPress, there is a default code which keeps the posts in the trash folder for 30 days. To change the default value, you have to edit the wp-config.php file.

The code is.

define(‘EMPTY_TRASH_DAYS’, 30);

But if you want to automatically empty WordPress trash in a few days then you can set it.

Step 1:- Login to your cPanel and open the file manager.

Step 2:- Search for the wp-config.php file and click to edit it. Add the below-written code.

define(‘EMPTY_TRASH_DAYS’, 10);

After adding this code, the trash folder will get emptied after every 10 days. It will provide you enough time to restore your post.

And if you want to change the frequency then just replace the figure in the code. You can set it from 1 to 29. But for the better site handling “10” days are perfect.

Sometimes you may accidently delete any blog posts from your published posts then it goes to the trash folder and you can restore it.

But if you minimize the empty days then maybe you won’t be able to restore the blog post.

Can You Now Set The Number To Empty WordPress Trash?

Most of the WordPress users get fed up with the load in the trash section. They try to manage it but for a bigger website, it’s a kind of hard to delete each and every post manually.

So to get rid of this problem, you should set the number of days to keep the posts in the trash folder. After that, all the posts will get deleted.

by Ravi Chahar

A blogger, web developer, and designer who intend to guide his readers about WordPress, Blogging, Web Development, Web Design and more. I have expertise in WordPress theme development and customization. I can set up and redesign the Thesis themes. I have been working in this field for years now.

4 comments

    1. Hey Lesly,

      Yeah, there is nothing hard in this code. WordPress is a platform to have fun with. You can learn a lot more about this CMS.
      Thanks for stopping by.
      Have a great weekend.
      ~Ravi

  1. Hi Ravi,
    This would be great for a large blog I would think. Every saving device of time is welcome.
    When working with code I always copy and past the original to a note doc before changing anything.
    Just in case. Thanks for the valuable tip.

    1. Hey Kathryn,

      The code can be used to reduce the default number of days. As you have mentioned about the benefit for the large websites, it would be really good to empty the trash before the default date.
      You should always keep the original code safe so that if everything goes wrong then you can use it.
      Thanks for sharing your thoughts.
      Have a great week ahead.
      ~Ravi

Leave a Reply

Your email address will not be published. Required fields are marked *

CommentLuv badge