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.

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.

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.

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.

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.

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.

Automatically Empty WordPress Trash

It should be noted that there is a solution for people who don’t like the Trash feature. These administrators can change the integer to “0” and avoid permanent deletion of the posts from the Trash menu.

As the Trash feature is available in WordPress versions higher than 2.9, the above-mentioned procedure is suitable for bloggers whose site runs on recently updated WordPress versions. Users whose websites are running on WordPress versions of 2.8 can not avail this feature from the core. However, they can avail the alternate method, i.e. using plugins for deleting Trash automatically.

There are tremendous numbers of plugins that can be used to customize the time interval for deleting the trash from the WordPress site automatically. Some of the most efficient plugins that fall into this category are Trash Emptier and RJ Quick Empty Trash. Using these plugins is as easy as any other simplified plugin for WordPress. The administrator only needs to install the plugin and customize it manually to set the automatic cleaning of Trash.

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 ;-)

WhatsWP is designed to help WordPress beginners start and manage a WordPress site easily by providing the tutorials and guides about WordPress coding stuff, blog writing, monetization, SEO, themes, plugins, web hosting, etc.

The site was founded in 2011 and renamed from WPMatter on May 5th 2015 by Joyce, Lucy and Eunge, who are professional WordPress geeks. Each of them has worked for WordPress matters for over 5 years. Now we're a small business in San Francisco with 20+ full-time staffs fully devoted into the online blogging business.

FTC Disclosure

We're paid by for the product listing, advertisement and referral. However, this does not affect our independent thought. We never accept the review & rating linked to payments at all. We always work hard and try our best to help people find reliable WordPress hosts and other products at an affordable rate, based on our real WordPress experience in the past 7 years.