Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Automatically Empty Your WordPress Trash

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

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, we will show you how to automatically empty your trash daily, weekly, or at any interval you want.

How to automatically empty your WordPress trash

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.

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 our 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?

Let’s see how you can automatically empty trash in WordPress after a certain time period.

We will cover two methods. You can use the links below to jump to your preferred method:

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

You can add this code snippet to your WordPress theme’s functions.php file. However, a tiny error in the code can break your website and make it inaccessible.

That’s why we recommend using WPCode. It is the best code snippets plugin for WordPress that allows you to safely add custom code to your website without breaking it.

First, you’ll need to install and activate the free WPCode plugin. For more details, please see our guide on how to install a WordPress plugin.

Note: WPCode also has a paid plan that you can install to unlock amazing features like a code snippet library, conditional logic, create a custom block, and more.

Upon activation, visit the Code Snippets » +Add Snippet page from the WordPress admin sidebar.

From here, click the ‘Use Snippet’ button under the ‘Add Your Custom Code (New Snippet)’ option.

Add new snippet

This will direct you to the ‘Create Custom Snippet’ page, where you can start by typing a title for your code snippet. It can be anything that will help you identify it.

After that, select the ‘PHP Snippet’ option as the ‘Code Type’ from the dropdown menu on the right.

Choose PHP as the code type

Next, simply copy and paste the following code into the ‘Code Preview’ box:

define('EMPTY_TRASH_DAYS', 1 ); //Integer is the amount of days

If you leave this code as it is, then your trash will be emptied every 24 hours.

However, you can simply change the number 1 in the code to some other number so that the trash will be emptied for that number of days.

For instance, you can write 15 instead of 1 in the code, as in the example below, and your WordPress trash will be emptied every 15 days:

define('EMPTY_TRASH_DAYS', 15 ); //Integer is the amount of days
Change the number to your liking in the code

If you set the number of days to 0, however, the WordPress trash feature will be removed entirely. WordPress will then permanently delete posts and pages without placing them in the trash.

Note: Make sure to have a backup of your WordPress website before activating this feature so that you can restore any accidentally deleted pages or posts.

Next, scroll down to the insertion section and choose ‘Auto Insert’ mode.

The custom code will be live on your site whenever you save the snippet.

Choose an insertion method

After that, scroll to the top of the page and toggle the ‘Inactive’ switch to ‘Active.’

Finally, don’t forget to click on the ‘Save Snippet’ button to store your settings and execute the code on your website.

Save the snippet for emptying trash in WordPress

Method 2: Automatically Empty WordPress Trash With a Plugin

If you don’t want to add code to your website, then this method is for you.

First, you’ll need to install and activate the Change Empty Trash Time plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, head over to the Settings » General page from the WordPress admin area.

Once there, scroll down to the bottom of the page where you will find a new ‘Time to empty trash’ option.

Use a plugin to empty trash in WordPress

Here, simply type in the number of days that WordPress should take to empty the trash. For example, you can type 1 for daily, 7 for weekly, or 30 for monthly.

If you type 0, then the deleted posts and pages will be deleted permanently instead of being placed in the trash.

Note: Be very careful about setting the time to empty to 0. It can be difficult to recover permanently deleted posts and pages. Make sure you are using a backup plugin, just in case.

Once you are done, don’t forget to click the ‘Save Changes’ button to store your settings.

Bonus: Create Your Website Backups

If you have removed the trash option and want to delete content from your site permanently, then we recommend creating a backup for your website first.

To do this, you can use Duplicator which is the best WordPress backup plugin on the market. It is super beginner-friendly and has amazing features like scheduled backups, recovery points, cloud storage integration, migration tools, and more.

Duplicator Plugin Mascot created by Solomon Balkhi

Upon plugin activation, visit the Duplicator Pro » Packages page and click the ‘Create New’ button in the top corner.

This will take you to a new screen where you must add a name for the backup that you are creating. After that, select a storage location and scroll down to the Archive section to customize your backup.

For instance, the plugin lets you only back up the database and filter files, folders, and extensions.

Archive settings for backup

Next, you have to fill in the additional settings in the installer and continue forward.

Duplicator will now perform a scan and make sure everything is in order to create a backup. Once that’s done, you can click the ‘Build’ button.

View scan of your package

You have now successfully created a site backup and can restore any content that you deleted accidentally. For detailed instructions, see our beginner’s guide on how to back up your WordPress site.

We hope this tutorial helped you learn how to automatically empty your trash in WordPress. You may also want to learn how to get a free SSL certificate or check out the list of best WooCommerce plugins for your online store.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

4 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. kenal says

    I found this very useful because even after deleting a post, slide or comment. Going to the trash to permanently empty it is always the next step. Makes me more lazy in regards to that which is cool.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WPBeginner Assistant
How can I help you?

By chatting, you consent to this chat being stored according to our privacy policy and your email will be added to receive weekly WordPress tutorials from WPBeginner.