How to Automatically Empty Trash in WordPress and Keep Your Site Clean

Date:

Share post:

Automatically Clear Your WordPress Trash: An Easy Guide

Introduction

Is your WordPress trash causing clutter on your website? WordPress automatically clears the trash after 30 days, but what if you want to clear it more frequently or less often? In this article, we will show you two methods to automatically empty your WordPress trash, so you can maintain a clutter-free website.

Method 1: Using a Code Snippet

If you want to automate the process of emptying your WordPress trash, you can start by using a code snippet. However, it is important to be cautious when adding custom code to your site. We recommend using the WPCode plugin, which allows you to safely incorporate custom code onto your site.

  1. Install and activate the free WPCode plugin on your WordPress site.
  2. Access the ‘Code Snippets’ page in your WordPress admin sidebar and click on ‘+Add Snippet’.
  3. Enter a title for your code snippet for future reference.
  4. Select ‘PHP Snippet’ as the code type.
  5. Copy and paste the provided code snippet below:
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( ! function_exists( 'wp_schedule_event' ) ) {
    require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}

function wpb_automatically_empty_trash() {
    wp_scheduled_delete();
}
add_action( 'wp_scheduled_delete', 'wpb_automatically_empty_trash' );
  1. By default, this code snippet will empty your trash every 24 hours. If you want to change the interval, replace the ‘1’ with your desired number of days. For example, if you want your trash to be emptied every 15 days, change ‘1’ to ’15’.
  2. Scroll down and select ‘Auto Insert’ mode for the insertion section.
  3. Toggle the switch from ‘Inactive’ to ‘Active’ at the top of the page.
  4. Click on ‘Save Snippet’ to store your settings and activate the code on your site.

Before activating this feature, it is essential to back up your WordPress site to avoid accidentally deleting important posts or pages.

Method 2: Using a Plugin

If you prefer not to add code directly to your website, you can use a WordPress plugin to automatically empty your trash.

  1. Install and activate the ‘Change Empty Trash Time’ plugin on your WordPress site.
  2. Navigate to ‘Settings’ > ‘General’ in your WordPress admin area.
  3. Scroll down to the ‘Time to empty trash’ option located at the bottom of the page.
  4. Set the number of days you want WordPress to wait before emptying the trash. For daily emptying, enter ‘1’. For weekly, enter ‘7’. To keep deleted posts and pages permanently, enter ‘0’.
  5. Be cautious when setting the time to empty to ‘0’, as this will result in permanent deletion of content. To ensure additional protection, consider using a backup plugin such as Duplicator.
  6. Click on ‘Save Changes’ to store your preferences.

That’s it! Your WordPress trash will now be automatically emptied based on your desired interval. Keeping your trash clean will optimize your website’s performance and improve the user experience.

We hope this easy guide has been helpful in assisting you in automating the process of emptying your trash in WordPress.

Subscribe to our newsletter

Stay ahead of the game! Subscribe to our newsletter for exclusive tips and insights on Data Structures & Algorithms and interview preparation.

Leave a Reply

Related articles

10 Effective Growth Hacking Techniques to Boost Your Online Influence**

The Influence of Online Power: 10 Techniques for Boosting Growth In today's digital world, having a strong online presence...

Boost Your Productivity with Checklists: An Essential Tool for Every Blogger and Marketer

The Power of Using Checklists: Enhancing Your Efficiency as a Blogger or Marketer In the fast-paced world we live...

Convert Webpages to PDFs: A Simple Guide**

Finding an easy and reliable way to convert webpages to PDF files can be a daunting task. Many...

Mastering Freelance Success: Key Tips for Building a Thriving Career

Keys to Creating a Successful Freelance Business: Essential Strategies and Techniques Introduction: Flourishing in the Freelance Economy As the gig...