Let WordPress automatically clean up your trash

Allot of WordPress users never empty their trash, what could result in a large amount of trashed posts. Since you’ll probably never use these posts again, we can let WordPress delete them automatically after a certain amount of days. We can enable this feature by adding the following line of code to our wp-config.php file.

define( 'EMPTY_TRASH_DAYS', 30 );

This example sets WordPress to automatically delete trashed posts after 30 days. We can also completely disable the trash feature, to do so add the following code to your wp-config.php.

define('EMPTY_TRASH_DAYS', 0 );

When we completely disable the trash the label for deleting a post will change from “(Move to) Trash” to “Delete Permanently”.

Related Posts

Powered By Related Posts for WordPress
Click Here to Learn More About Related Posts for WordPress

10 thoughts on “Let WordPress automatically clean up your trash

  1. […] Let WordPress automatically clean up your trash » […]

  2. oh, if this was a standard option. so nice.

  3. wp-config saves the day. I was hoping to find a clean solution like this. Thank you!

  4. nice.. how about live posts? I mean I wish to set an expiration dates to lives posts which are supposed to be deleted from the database after 7 days or so. How to execute this via wp-config file?

    PS: I want this because I plan to open a newspaper based site where posts after 30 days are not required anyway.

    • As far as I know, this is not possible through a wp-config setting. There are some plugins out there that can do this for you. A quick search led me to http://wordpress.org/plugins/auto-prune-posts/ , I’ve never used it but it seems to fit your needs. Good luck!

      • oh!! such a quick reply. thanks man.. it’s sad that this function cannot be executed via wp-config file.

        And, thanks foe the plugin but unfortunately this is not update for close to 2 years and I am afraid this will not be compatible with the latest WP version. Anyway, let me search on this and I will get back to you if I find something worth sharing..
        Anyway thanks for your time.

  5. That was a quick fix, thanks!

  6. Thanks for sharing this information. If I set the trash to empty every day — define( ‘EMPTY_TRASH_DAYS’, 1 ); — specifically what time of day does the event take place? Midnight? Noon? Randomly?

    I’ve googled for about an hour looking for the answer. Strangely, it seems that nobody has ever brought it up because I can’t find any details about it.

    • Cor van Noorloos

      The wp_scheduled_delete cron event is scheduled daily at midnight.
      To answer my own question, which is how Google guided me here. Content deleted before EMPTY_TRASH_DAYS was set to '0' will also be deleted by this daily event.

  7. Thanks Barry… did you know can also stop the empty trash automation?

Leave a Reply

Your email address will not be published. Required fields are marked *