Discover in this tutorial how to empty the WordPress trash automatically by code.
WordPress has, along with the auto-save system, another that manages the items sent to the trash, like:
- Posts.
- Pages.
- Objects.
- Comments.
By default, WordPress empties the trash every 30 days.
Would you prefer to decrease or increase the time in which items are deleted from the WordPress trash?
Well, you only need one line of code to customize the frequency.
Snippet to change the frequency of emptying the WordPress Trash
Add the following fragment at the end of the wp-config .php file:
To see this and another 1097 code snippets of this website, login or subscribe here.
From now on the trash will be emptied every 7 days.
Are you interested in modifying this time? Customize the number in the snippet to your liking (always in days).
If you prefer to delete items directly without them going through the trash, you can set it to zero. Like this:
To see this and another 1097 code snippets of this website, login or subscribe here.
Conclusion
As you can see, with one line of code you can decide how often should be deleted the items that you send to the WordPress trash.
And if you want, you can combine this with the limitation of the number of revisions to keep this section of WordPress 100% under control.
Any questions? I read you in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉