wordpress empty trash
GuideWordpress
2

How to Adjust Automatically Empty Trash on WordPress

If you look at the code from WordPress under the file “\wp-includes\default-constants.php”. By default, it would automatically empty the trash after 30 days. However, you might want to keep it longer or shorter. In this guide, we will walkthrough how we can adjust the days to empty trash automatically.

There are two ways to control the number of days you want to empty the trash,

  • Using a plugin. This method will be much easier and straight forward, since you just need to install and configure from the WordPress settings.
  • Modifying the code. This method is straight forward as well but you will need to modify the code and the code could be replace if you update your WordPress.

Method 1 : Adjust number of days to empty trash by installing a plugin

First, install “Change Empty Trash Time”

empty trash time

“Change WP Empty Trash Time” is a small plugin that allows you to select the time in days that WordPress take to automatically empty trash. You can select the number of days at the bottom of Settings > General. This plugin wont work if the value is already defined elsewhere to avoid errors.

Features

  • Allow to select the days that WordPress take to empty trash.
  • Automatically Empty Trash after the numbers of days selected

After installing the plugin, go to settings > general and you should see the empty trash settings

empty trash
Here you will be able to adjust the time to empty trash

Method 2 : Adjust number of days to empty trash by code

This is actually pretty easy, open up the file “wp-config.php” and add in the following line.
define('EMPTY_TRASH_DAYS', 1);
For example below,

empty trash days

Just adjust the number of days you want to keep the post.
From the example above, I’ve set it to “1” which means that the posts will be kept in the trash for 1 day only.

How to Stop WordPress from Automatically Emptying Trash ?

You might not want to delete your trash at all to keep it as long as you want until you decide to remove it manually and here how you can achieve that. You will need to add some codes in the “function.php” file in order to disable automatic empty trash.

function wpb_remove_schedule_delete() {
remove_action( 'wp_scheduled_delete', 'wp_scheduled_delete' );
}
add_action( 'init', 'wpb_remove_schedule_delete' );

The “function.php” file should be under your theme folder, for example “\wp-content\themes\colormag\functions.php”

NOTE : This might not be the best method to disable automatic empty trash feature on WordPress. This is because once you update your template, the code might be gone and you will need to modify the file to add that function again. You may look for a plugin or create your own plugin to keep this setting permanently.

More WordPress tips : How to Use Shortcode in WordPress (Including Custom Template)

2 thoughts on “How to Adjust Automatically Empty Trash on WordPress

Comments are closed.