How to delete trash in WordPress automatically?

WordPress trash can be deleted manually by clicking on the Empty Trash button. But you can also automate the process. This can be done using the wp-config.php file. This file can make a decision after what interval the WordPress trash needs to be cleaned. 

By default, WordPress cleans the trash after 30 days. To change this interval, open your wp-config.php file. This file is located in the root directory. 

After you have opened the file, search for the line saying;

define( ‘EMPTY_TRASH_DAYS’, 30 ); ​

You can change the number from 30 to any number. By doing so, the interval will change. For example, you can change it to 5 days by changing the number to 5.

define( ‘EMPTY_TRASH_DAYS’, 5 ); ​


In order to disable the trash, you can change the value to 0. So the code will become:

define( ‘EMPTY_TRASH_DAYS’, 0 ); ​

It is not advisable to change the value to 0 as you can lose your important entries. So change the number to a minimum value, so that the trash gets removed on a regular basis.

That's it. This is how you can delete your WordPress trash automatically.

Did you find this article useful?