How To Automatically Empty WordPress Trash Using Days Parameter?
October 9th, 2016 | by Ravi Chahar || 4 Comments |
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.
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.
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.
Very helpful! I have to admit I get nervous working with code. I always think I’m going to mess something up… But I am learning. Thank you for this, did not seem so hard!
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.
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.
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.