How to automatically clear WordPress bins
Apr 20, 2025 am 06:09 AMDo you want the junk on your WordPress website to be automatically emptied?
By default, WordPress automatically deletes everything in the trash for 30 days. However, some users may prefer to clear the garbage more or less.
In this article, we will show you how to automatically clear the garbage every day, weekly, or at any time interval you want.
What is garbage in WordPress?
WordPress added the trash function as early as version 2.9. It works like a recycling bin or trash can on a computer.
In other words, the posts you delete are not deleted immediately, but are sent to the trash. Therefore, you can restore them before you permanently delete them after a period of time.
Anyone could accidentally click on the “Delete” link on the post. That's why WordPress can easily recover deleted posts and pages.
Your WordPress website will automatically delete everything in the trash after 30 days so that they don't pile up and continue to use server resources.
If you want to prevent WordPress from automatically clearing the bin, you can follow our guide to how to disable automatic clearing the bin in WordPress.
But what if you want to empty the trash regularly instead of once a month?
Let's see how to automatically clear the trash in WordPress after a while.
We will introduce two methods. You can use the link below to jump to your preferred method:
- Method 1: Use WPCode to automatically clear WordPress trash bin (recommended)
- Method 2: Use plugins to automatically clear WordPress trash
Method 1: Use WPCode to automatically clear WordPress trash bin (recommended)
For this method, we will automatically clear the trash in WordPress using a custom code snippet.
You can add this code snippet to the functions.php file of the WordPress theme. However, a tiny bug in the code can break your website and make it inaccessible.
This is why we recommend using WPCode. It is the best code snippet plugin for WordPress, allowing you to safely add custom code to your website without breaking it.
First, you need to install and activate the free WPCode plugin. For more details, see our WordPress plug-in installation guide.
Note: WPCode also has a paid plan that you can install to unlock amazing features such as code snippet libraries, conditional logic, creating custom blocks, and more.
Once activated, access the Code Snippets ? Add Snippets page from the WordPress Management sidebar.
From here, you have to click the Use Code Snippet button under the "Add Custom Code (New Code Snippet)" option.
This will lead you to the Create Custom Code Snippets page where you can start typing the title of the code snippet. It can be anything that can help you identify it.
After that, select the "PHP Snippet" option as "Code Type" from the drop-down menu on the right.
Next, just copy and paste the following code into the Code Preview box:
However, if you set the number of days to 0, the WordPress trash feature will be completely removed. WordPress will then permanently delete posts and pages without putting them in the trash.
Note: Before activating this feature, make sure to back up your WordPress site so that you can recover any accidentally deleted pages or posts.
Next, scroll down to the Insert section and select “Auto Insert” mode. Now, as long as you save the code snippet, the custom code will take effect on your website.
After that, scroll to the top of the page and switch the Inactive switch to Active.
Finally, don't forget to click the "Save Fragment" button to store your settings and execute code on your website.
Method 2: Use plugins to automatically clear WordPress trash
If you don't want to add code to your website, this method is for you.
First, you need to install and activate the Change Empty Junk Time plugin. For more details, see our step-by-step guide on how to install WordPress plug-ins.
Once activated, go to the Settings ? General page from the WordPress admin area.
Once there, scroll down to the bottom of the page where you will find the new "Time to Empty Trash" option.
Here, just enter the number of days it takes for WordPress to empty the bin. For example, you can type 1 for daily, 7 for weekly, or 30 for monthly.
If you enter 0, deleted posts and pages will be permanently deleted instead of being placed in the trash.
Note : Be very careful when setting the clear time to 0. Recovering permanently deleted posts and pages can be difficult. Make sure you use the backup plugin just in case. To do this, we recommend using a replicator.
When you are done, don't forget to click the "Save Changes" button to store your settings.
We hope this tutorial helps you understand how to automatically clear the trash in WordPress. You may also want to learn how to get a free SSL certificate or view a list of the best WooCommerce plugins for your online store.
The above is the detailed content of How to automatically clear WordPress bins. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Contents 1. What is ICN? 2. ICNT latest updates 3. Comparison and economic model between ICN and other DePIN projects and economic models 4. Conclusion of the next stage of the DePIN track At the end of May, ICN (ImpossibleCloudNetwork) @ICN_Protocol announced that it had received strategic investment in NGPCapital with a valuation of US$470 million. Many people's first reaction was: "Has Xiaomi invested in Web3?" Although this was not Lei Jun's direct move, the one who had bet on Xiaomi, Helium, and WorkFusion

The latest version of Binance is v2.102.5, and the update tutorial is: 1. Click the download link in the web page; 2. Authorize the installation permission of "Allow installation from unknown sources"; 3. Find the downloaded APk and click to install; 4. Click the installed application to open it.

The latest version of Binance is v2.102.5, and the update tutorial is: 1. Click the download link in the web page; 2. Authorize the installation permission of "Allow installation from unknown sources"; 3. Find the downloaded APk and click to install; 4. Click the installed application to open it.

The latest version of Binance is v2.102.5, and the update tutorial is: 1. Click the download link in the web page; 2. Authorize the installation permission of "Allow installation from unknown sources"; 3. Find the downloaded APk and click to install; 4. Click the installed application to open it.

The latest official version of the virtual currency trading platform v6.129.0 is a professional and secure digital asset trading application created for Android users. It provides rich market conditions, convenient trading functions and multiple security protection, and is committed to providing users with a first-class trading experience.

The latest version of Binance is 2.101.8, and the update tutorial is: 1. Click the download link in the web page; 2. Authorize the installation permission of "Allow installation from unknown sources"; 3. Find the downloaded APk and click to install; 4. Click the installed application to open it.

The latest version of Binance is 2.101.8, and the update tutorial is: 1. Click the download link in the web page; 2. Authorize the installation permission of "Allow installation from unknown sources"; 3. Find the downloaded APk and click to install; 4. Click the installed application to open it.

As the market conditions pick up, more and more smart investors have begun to quietly increase their positions in the currency circle. Many people are wondering what makes them take decisively when most people wait and see? This article will analyze current trends through on-chain data to help readers understand the logic of smart funds, so as to better grasp the next round of potential wealth growth opportunities.
