In WordPress, when delete a post or comment, it goes into trash. By default, trashed posts and comments remain in your database for 30 days giving you enough time to restore them if needed. After 30 days, WordPress automatically deletes all trash content permanently. In this article, we will show you how to limit or disable automatic WordPress empty trash feature.
What is Trash in WordPress?
When you delete a post, page, or a comment in WordPress, it is marked as trash.
You can see the trashed posts or comments by clicking on the Trash link when viewing posts, pages, or comments.
By default, these items will remain there for 30 days. After that, WordPress will automatically delete them permanently.
You can override the automatic process by going to trash and deleting the items manually by clicking on the delete permanently link.
But what if you don’t want WordPress to delete items from trash? Or maybe you want WordPress to automatically delete items sooner or later than 30 days.
Let’s take a look at how to limit or disable automatic WordPress empty trash feature.
Stopping WordPress from Automatically Emptying Trash
Do you want to stop WordPress from automatically deleting items from trash? Here is what you need to do.
This code simply removes the action that deletes trashed items when their time is up.
Now when you send an item to trash, it will remain there until you go to trash and manually empty the trash.
Changing When to Empty Trash in WordPress
As we mentioned earlier, WordPress automatically empty trash after 30 days. You can change this to any number of days you want.
Simply add the following line of code in your wp-config.php file just before the line that says ‘That’s all, stop editing! Happy blogging.’
This line changes the trash emptying schedule to 7 days. You can change 7 to any number of days that you want.
Disabling The Trash Feature in WordPress
We don’t recommend disabling the trash functionality in WordPress. It is a great feature that comes in handy when you accidentally delete a post, page, or a comment.
However, if you really feel that you don’t need this functionality, and you would rather delete things permanently, then here is what you need to do.
Simply add this line of code in your wp-config.php file just before the line that says‘That’s all, stop editing! Happy blogging.’
That’s all, we hope this article helped you learn how to limit or disable automatic empty trash feature in WordPress.