How To Restrict Or Disable The Automatic Cleaning Of WordPress Recycle Bin

3 minutes read

In WordPress, when you delete a post or comment, they are placed in the trash. By default, records and comments in the cart remain in your database for 30 days, giving you enough time to restore them if necessary. After 30 days, WordPress automatically deletes all content from the recycle bin forever. In today’s article, we will show you how to limit or disable the automatic cleaning of the WordPress Recycle Bin.

What Kind Of Cart In WordPress?

When you delete a post, page, or comment in WordPress, it is marked as trash.

Trash In WP Posts

You can see deleted posts or comments by clicking the Trash link when viewing posts, pages and comments.

By default, these items remain there for 30 days. After that, WordPress automatically removes them permanently.

You can intervene in the automatic process, if you go to the cart and delete items manually, click on the Delete link permanently.

Delete Trash

But what to do if you don’t need to remove items from the recycle bin. Or you want WordPress to automatically delete items earlier or later than 30 days.

Let’s see how you can limit or disable the automatic cleaning of the WordPress Recycle Bin.

Turning Off The Automatic Recycle Bin In WordPress

Do you want to wean WordPress from automatically deleting items from the recycle bin? Here’s how to do it.

Simply add the following small piece of code to the functions.php file of your theme or to the plugin for the WordPress site :

1 function devise_remove_schedule_delete() {
2     remove_action( 'wp_scheduled_delete''wp_scheduled_delete' );
3 }
4 add_action( 'init''devise_remove_schedule_delete' );

This code simply removes the action, which removes items from the cart upon expiration.

Now, when you put the items in the trash, they will remain there until you manually empty the trash.

Change The Retention Period Of Items In The WordPress Shopping Cart

As we said earlier, WordPress automatically cleans the recycle bin after 30 days. You can change this number to any according to your desire.

Just add the following line of code to your wp-config.php file right before the line ‘This is all, do not edit further. Successes! ‘

1 define('EMPTY_TRASH_DAYS', 7);

This line changes the schedule of cleaning the basket for 7 days. You can change 7 for any number of days at your discretion.

Disable Recycle Bin In WordPress

We do not recommend turning off recycle bin functionality in WordPress. This is a great feature that comes in handy when you accidentally delete a post, page or comment.

However, if you really need to disable this feature, and you prefer to delete it immediately and permanently, here’s how you can do it.

Just add this line of code to your wp-config.php file right before the line ‘That’s all, we’re not editing any further. Successes! ‘

1 define('EMPTY_TRASH_DAYS', 0);

Adding this line will completely disable the recycle bin feature in WordPress. For all your posts and pages, arbitrary post types, comments pages you will see the Delete forever link instead of deleting to the trash.

Trash Disabled

That’s all, we hope that this article has helped you learn to limit or disable the automatic cleaning of the WordPress Recycle Bin.

For all questions and feedback, please write in the comments below.

Do not forget, if possible, to rate your favorite records by the number of stars at your discretion.

Facebook Twitter LinkedIn Telegram Pocket

Related Posts:

Would you like to turn off email notification about automatic WordPress update? By default, WordPress sends email notifications to inform you that security updates have been installed on your site. Recently, a reader asked if there was a way to disable these e...
In WordPress 4.4, the long awaited JSON REST API has been added. This is a great plugin for developers, but for many site owners it is simply useless. In this article, we will show you how to easily disable the JSON REST API in WordPress. Why Do I Need To Disa...
To disable WordPress plugins, you can follow these steps:Log in to your WordPress admin panel.From the admin dashboard, go to the "Plugins" tab.On the "Plugins" page, you'll find a list of all installed plugins.Locate the plugin you want to...