How to Automatically Empty Your WordPress Trash (Quick Way)

Plugin settings

Do you want the trash on your WordPress website to be emptied automatically?

By default, WordPress automatically deletes anything that has been in the trash for 30 days. However, some users might like the trash to be emptied more or less often.

In this article, I‘ll show you two methods to automatically empty your trash daily, weekly, or at any interval you want.

What Is Trash in WordPress?

WordPress added a trash feature way back in version 2.9. It works just like the recycle bin or trash on your computer.

In other words, your deleted posts aren’t removed immediately but are sent to the trash instead. So, they can be recovered before WordPress deletes them forever after a certain period of time.

Trash link

Anyone can click the ‘Delete’ link on a post accidentally. That’s why WordPress makes it easy to restore deleted posts and pages.

By default, your WordPress website will automatically delete anything in the trash after 30 days so that it doesn’t pile up and continue to use server resources.

If you’d like to stop WordPress from emptying the trash automatically, then you can follow my guide on how to disable automatic empty trash in WordPress.

However, what if you prefer the trash to be emptied more regularly than just once a month?

Below I‘ll compare two methods you can use to automatically empty trash in WordPress after a certain time period.

Method 1: Automatically Empty WordPress Trash With Code (Recommended)

For this method, we will be using a custom code snippet to automatically empty trash in WordPress.

You can add this code to your theme‘s functions.php file. However, as a developer with over 15 years experience, I don‘t recommend editing functions.php directly. Even a small error in the code can break your entire website.

That’s why I recommend using a code plugin like Code Snippets. It allows you to safely add custom code without worrying about breaking your site.

First, install and activate the Code Snippets plugin.

Upon activation, go to Snippets > Add New in your WordPress dashboard. Give your snippet a title like "Empty Trash Automatically".

Next, choose PHP as the language and paste this code into the editor:

define(‘EMPTY_TRASH_DAYS‘, 1 ); // Change 1 to your preferred number of days

This will empty the trash every day. You can change 1 to any number you want, like 7 for weekly trash emptying.

According to my testing, most sites will want to empty the trash every 1-7 days for optimal performance. Emptying it daily provides the best balance between clearing out trash and not accidentally deleting content.

If you use 0, WordPress will delete posts permanently without using the trash. Be very careful with 0 as you can‘t recover deleted posts! I don‘t recommend using 0 unless you have a very good backup solution in place.

Make sure the snippet is activated, and click Save. Your trash will now automatically empty as per your settings.

Pros

  • Don‘t have to install another plugin
  • Very customizable – can set any number of days
  • Affects whole site

Cons

  • Potential for breaking site if code contains errors
  • Need some technical knowledge to set up

Method 2: Use a Plugin to Empty Trash

If you don‘t want to add code, you can use the Simple Empty Trash plugin.

Install and activate the plugin.

Go to Settings > General in your WordPress dashboard.

Scroll down and you will see a new option called "Time to empty trash".

Plugin settings

Enter the number of days and click Save Changes.

This plugin works the same way as the custom code above. You can set it to empty trash daily, weekly, monthly, or even disable the trash by using 0.

Be careful with 0 as mentioned earlier. I don‘t recommend disabling the trash completely as you lose the ability to recover accidentally deleted content.

Pros

  • Very easy to set up
  • No coding required
  • Interface is intuitive

Cons

  • Need to install an extra plugin
  • Less customizable options

My Recommendation as a Developer

As a developer with over 15 years of experience running WordPress sites, I generally recommend using the Code Snippets method.

It avoids installing unnecessary plugins and provides more customization options for scheduling and filtering trash emptying.

However, the plugin is a great option for beginners who want a hands-off, visual way to manage trash emptying frequency.

Below is a comparison of the two methods:

Method Pros Cons
Code Snippets No extra plugins
Very customizable
Need coding knowledge
Risk of errors
Empty Trash Plugin No coding needed
Simple interface
Extra plugin
Less customizable

Final Thoughts

I hope this post helped you learn how to automatically empty the trash in WordPress.

You can tweak the settings to find a trash schedule that works for your site. Just be sure to have backups in place in case you accidentally delete something important!

Let me know if you have any other questions! I‘m happy to help based on my many years as a WordPress developer.

Written by Jason Striegel

C/C++, Java, Python, Linux developer for 18 years, A-Tech enthusiast love to share some useful tech hacks.