What's WP
Our everything is about WordPress - best choice of WordPress users!
How to Control the WordPress "Automatic Delete Trash" Feature

How to Control the WordPress “Automatic Delete Trash” Feature

Since the version 2.9, WordPress have been coming with a helpful trash feature. When you delete the useless posts, pages or comments, they are categorized as “trash” in WordPress dashboard, and they will remain in trash until WordPress deletes them automatically after 30 days.

During the 30 days, you can manually delete the trash permanently, or restore the posts, pages and comments that have been deleted accidently.

WordPress Trash

The default configurations of WordPress “automatic delete trash” feature are good to use for most people. However, you may want to take full control and do things like shortening the days for trashed posts to remain, disable the automatic deleting, etc. If you have any needs like this, just follow the very simple tutorials below to achieve what you want.

Lengthen or Shorten the Days for WordPress to Delete Trash

By default, WordPress deletes the trashed posts, pages and comments permanently from the database after 30 days of their deletion. However, WordPress indeed gives you the freedom to control the frequency, so you can automate the trash emptying to perform daily, weekly, per 10 days, or with any other frequency you want.

No plugin is needed for changing the days, because all you need to do is to locate the wp-config.php file in your WordPress directory, open it in a text editor, and then add the following line of code before the “Stop Editing” line.

Change the Days for WordPress to Delete Trash

The number “1” in the example above indicates that trashed content will be deleted one day after it is moved to trash. Of course, you can change the number to whatever you like. For example, if you want WordPress to empty trash after a week, then replace “1” with “7”. The same change comes to “10” or any other number of days.

Prevent WordPress from Deleting Trash Automatically

Sometimes you may want to disallow WordPress to delete trash automatically because you would like to do everything manually to prevent the mistakenly trashed posts from being deleted.

In such a case, you can remove the WordPress deleting trash action by adding the following code in the functions.php file of your theme.

Prevent WordPress from Deleting Trash

This function stops the scheduled trash deleting action from operating, so the trash posts will remain even if the configured deletion days have passed by already. Therefore, posts, pages and comments stay in trash until you delete them or empty trash manually.

Disable WordPress Trash Feature

Besides the two occasions discussed above, there is also a rare case that you may want to disable the WordPress trash feature temporarily. This usually happens when you are working on a staging site or a local development environment. If you create a large number of posts or comments for testing purpose, you may prefer to delete posts directly from the post list instead of moving them to trash and then spending time deleting them again.

If this is what you want, add the code below to the wp-config.php file.

Disable WordPress Trash Feature

With this code, the trash feature is disabled for all your posts, pages, comments and custom post types. You will get a link “Delete Permanently” instead of the ordinary “Trash”. You can then delete posts immediately.

Delete Permanently

Note that we don’t recommend disabling the trash feature on any production site. Even if on a staging site, you should be careful because without the trash feature, you don’t get a chance to think twice about the content you delete.

Author

Joyce is a professional writer & SEOer who loves trying new things and sharing the experience through blogging. She loves clean design, playing with different WordPress themes, SEO, etc. Now she is very struggle with purchasing a bubbling apartment in downtown. You can help her by clicking our ADs or making a purchase via our links ;-)

Close

Want to Learn More About WordPress?

Get Our Free Themes, Plugins, Support, SEO Tips, and Other Tutorials!

Email *