Home Blog

Automatically Delete trash in WordPress

September 13, 2017 | Pratik Bhavsar |


Do you want to delete trash periodically in WordPress? When we delete any Page or Post, it does not get deleted from database. WordPress keeps such deleted content in trash. This feature was introduced in wordpress version 2.9. Trash means keeping your content soft deleted that means your Post or Page deleted from website but not from database. By this way we can restore our content anytime.

However, keeping your content in trash for a long period is not a good practice. By doing so we are increasing our database size. It can be a case where your server provides you limited space. So it is recommended to empty your trash content regularly.

WordPress by default empty the trash every 30 days. For a website with large content 30 days period is comparatively long. These website owners might want to clear this trash content frequently.

But again, to perform this task you should keep reminding yourself. What if there is some automated system which does this job for you periodically in background?

In this article, we show you how to delete trash in WordPress automatically. You should have basic knowledge about editing files in WordPress.

Editing wp-config.php

Go to your project root directory and open wp-config.php file in your editor. We need to place one line of code in the file as below.

define('EMPTY_TRASH_DAYS', 7 );

/* That's all, stop editing! Happy blogging. */

In the above code, second argument 7 represents the amount of days after which you want to flush your trash periodically.

Above code will flush your trash after every 7 days.

It's all about deleting your trash automatically. We hope you understand how to delete trash in WordPress automatically.

If you have any questions or suggestion, please leave a comment below.

About the author


Pratik Bhavsar

Expert in WordPress, Laravel, AngularJS and MongoDB. Pratik likes to share his knowledge with community through blogging.