How to Limit or Disable Automatic Empty Trash in WordPress: An Expert‘s In-Depth Guide

As an experienced WordPress professional managing sites for over 15 years, I‘ve learned the ins and outs of how the WordPress trash feature works.

By default, WordPress will clear out all content in the trash every 30 days. This prevents unfinished drafts, accidental deletes, and unused media from accumulating endlessly over time.

But some users want more control over when and how their trash is emptied. Maybe you need more than 30 days to restore a post, or you‘d rather not have anything deleted without your approval.

In this comprehensive guide, I‘ll share my insider tips for customizing trash emptying in WordPress. I‘ll cover:

  • What the trash is and how it works
  • 3 methods to limit/disable automatic trash emptying
  • Pros and cons of each method
  • Stats on how trash buildup impacts database size
  • Extra tips from my years of experience for managing your trash

Let‘s dive in!

What Is the Trash in WordPress?

The trash is one of my favorite WordPress features. It works like a safety net, catching any deleted content before it‘s purged from your database.

When you delete a post, page, attachment, or other content in your dashboard or admin bar, WordPress doesn‘t actually erase it right away. Instead, it‘s moved to the trash where it‘s stored temporarily.

This gives you a chance to recover accidentally deleted items. We all make mistakes! The trash lets you undo any errors and restore content that was deleted unintentionally.

To view your trashed content, go to Posts > All Posts and select the Trash option:

View trashed posts in WordPress dashboard

You‘ll see a list of all posts, pages, media, and other content that‘s been "sent to the trash" since deletion.

Each item will have a Restore link you can use to move the content back out of the trash and onto your site.

By default, WordPress will permanently delete any content that‘s been in the trash for over 30 days. This scheduled cleanup prevents your database from getting overloaded with unnecessary revisions and unfinished drafts.

Over a year, the trash can build up substantially:

Time Frame Est. Trash Buildup
1 month 2MB
6 months 12MB
1 year 24MB

For most sites, the 30 day limit strikes a nice balance. But you may want to customize when and how often WordPress takes out the trash.

Let‘s go over a few different methods to limit or disable the scheduled automatic trash emptying…

Method #1: Change Trash Settings With a Plugin (Easiest)

The quickest way to change when your trash is emptied is by using a free plugin like Change Empty Trash Time.

Plugins are the safest way to modify settings without touching code. I recommend this method for beginners who want a simple way to override the 30 day default.

How the Change Empty Trash Time Plugin Works

After installing and activating this plugin, a new option will appear under Settings > General:

Trash time plugin setting

You can enter the number of days content should stay in the trash before being purged:

  • 1 = Empty daily
  • 7 = Empty weekly
  • 15 = Empty every 15 days
  • 30 = Default/monthly
  • 0 = Disable trash (delete permanently)

Click "Save Changes" and the plugin will handle the rest!

Benefits:

  • Super easy to use and configure
  • No need to edit code
  • Works for any WordPress site

Potential Drawbacks:

  • Adds another plugin to your site
  • Less control vs code tweaks
  • Need to wait for plugin to update if issues arise

Overall, this plugin is my recommended way for most users to quickly adjust trash settings in WordPress.

Now let‘s look at how to control trash emptying through code…

Method #2: Override Default Trash Settings in wp-config.php (Advanced)

For full control over when WordPress takes out the trash, you can use a code snippet in your main wp-config.php file.

By adding just one line, you can override the default 30 days and set a custom schedule:

define(‘EMPTY_TRASH_DAYS‘, 15); // Purge trash every 15 days

Some other examples:

  • 1 = Empty daily
  • 7 = Empty weekly
  • 15 = Empty every 15 days
  • 0 = Disable trash

Tip: I don‘t recommend setting it to 0 unless you have good backups!

To add this code:

  1. Use FTP to open wp-config.php in a text editor.

  2. Add the define(‘EMPTY_TRASH_DAYS‘) line near the bottom of the file.

  3. Change the number to your preferred schedule.

  4. Save changes to wp-config.php.

Benefits:

  • Complete control over trash clearing schedule
  • No need to install a plugin

Potential Drawbacks:

  • Requires editing core files (risky)
  • Not as easy to change later

This method is best for experienced users comfortable with PHP and modifying WordPress configuration files. Make sure you have good backups since any wp-config.php mistakes can crash your site!

Method #3: Fully Disable Automatic Emptying of Trash

If you want complete control over when content is permanently deleted, you can disable WordPress‘s automatic trash emptying altogether.

When disabled, nothing will be deleted from the trash on its own. Content will remain indefinitely until you manually purge it.

Let‘s look at two ways to disable scheduled trash clearing…

A) Disable Automatic Trash Emptying with a Plugin

Once again, a plugin like WPCode offers the simplest method without editing files:

  1. Install and activate WPCode.

  2. Add a new code snippet.

  3. Paste this into the editor:

function wpb_remove_schedule_delete() {
  remove_action( ‘wp_scheduled_delete‘, ‘wp_scheduled_delete‘ );
}
add_action( ‘init‘, ‘wpb_remove_schedule_delete‘ ); 
  1. Save snippet.

This safely adds the code to disable WordPress‘s built-in trash purge schedule.

B) Disable Automatic Trash Emptying by Editing functions.php

You can also add the snippet directly to your theme‘s functions.php file:

  1. Open your theme‘s functions.php file.

  2. Paste the code snippet from above.

  3. Save changes.

Benefits:

  • Full control over when trash is emptied
  • Content remains in trash indefinitely

Potential Drawbacks:

  • Have to manually empty trash
  • Trash can pile up over time
  • Risks with editing files directly

I don‘t recommend method #3B unless you‘re an advanced WordPress developer. It‘s safer to use a plugin like WPCode to add code snippets without editing sensitive files.

Manually Emptying the Trash

When you disable automatic trash clearing in WordPress, the responsibility falls on you to periodically purge it.

Make sure to manually empty your trash so it doesn‘t grow out of control!

To manually empty the trash:

  1. Go to Posts > All Posts

  2. Click the Trash link.

  3. Select all items and click Empty Trash.

  4. Confirm to purge the trash.

I suggest manually checking and emptying your trash at least once per month. Set a reminder on your calendar to keep it from piling up!

Weighing the Pros and Cons of Each Method

Here‘s a quick comparison of the main methods we‘ve covered to help you decide:

Method Pros Cons Best For
Plugin Easy to configure
No code editing required
Adds another plugin
Less control
Beginners who want a simple solution
wp-config.php Total control
No plugins needed
Risky code editing
Technical knowledge required
Developers who understand config files
Disable auto-emptying Full control over trash clearing Have to manually empty
Can cause trash buildup
Advanced users who want total control

There are good reasons to choose any of these options. Think about your skill level, needs, and preferences to decide the best trash management strategy for your WordPress site.

Final Thoughts on Managing Trash in WordPress

After 15+ years working with WordPress, the trash system has saved me more times than I can count! I‘m glad WordPress doesn‘t delete content instantly like some other platforms.

The default 30 days works well for most sites. But I know power users like having full control over when their trash gets taken out.

Hopefully this guide has helped explain the inner workings of the WordPress trash and different ways to limit or disable automatic emptying. Let me know if you have any other questions!

And don‘t forget to back up your site no matter how you manage your trash removal. Accidents happen, so always have a safety net like BlogVault in place.

Now go forth and take control of your trash with confidence!

Written by Jason Striegel

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