Cloud Service >> Knowledgebase >> WordPress >> Learn to Delete Trash in WordPress Automatically
submit query

Cut Hosting Costs! Submit Query Today!

Learn to Delete Trash in WordPress Automatically

Deleting trash in WordPress automatically is a good way to manage your website’s database and keep it clean. WordPress moves deleted posts, pages, comments, and other content to the trash, where they remain for 30 days before being permanently deleted. However, you can change this behavior to automatically delete trash more frequently or even disable the trash feature entirely.

Here’s how you can manage trash deletion in WordPress:

1. Adjust the Auto Trash Deletion Timeframe

You can change the number of days WordPress retains items in the trash before permanently deleting them.

Steps:

1. Access Your WordPress Files:

You’ll need to edit the wp-config.php file located in the root directory of your WordPress installation.

You can access this file via FTP, a file manager in your hosting control panel, or using a file manager plugin in WordPress.

2. Edit wp-config.php:

Open the wp-config.php file for editing.

Add the following line of code near the top, but after the opening tag:
php
Copy code
define('EMPTY_TRASH_DAYS', 7);

 

Replace 7 with the number of days you want WordPress to wait before automatically emptying the trash. The default is 30 days.

If you set this value to 0, WordPress will disable the trash feature entirely, meaning items will be permanently deleted immediately instead of going to the trash.

Save the file after editing.

2. Disable Trash Completely

If you don’t want to use the trash feature at all and want WordPress to permanently delete items immediately, you can set the EMPTY_TRASH_DAYS to 0.

Example:

php

Copy code

define('EMPTY_TRASH_DAYS', 0);

With this setting, anything you delete will bypass the trash and be permanently removed.

3. Schedule Automatic Trash Deletion via a Plugin

If you prefer not to edit code, you can use a plugin to manage trash deletion.

Recommended Plugins:

WP-Sweep: This plugin allows you to clean up your WordPress database by removing unnecessary data such as revisions, auto drafts, and items in the trash. It can be configured to run automatically at scheduled intervals.

Advanced Database Cleaner: This plugin helps you optimize your database and can automatically delete trash, spam comments, revisions, and more.

Steps:

Install and Activate the Plugin:

Go to Plugins > Add New in your WordPress dashboard.

Search for the desired plugin (e.g., WP-Sweep or Advanced Database Cleaner).

Click Install Now and then Activate.

Configure Automatic Deletion:

Follow the plugin’s documentation to set up automatic trash deletion according to your preferences.

4. Manual Trash Deletion

If you prefer manual control, you can regularly empty the trash from your WordPress dashboard.

Steps:

Go to Posts > All Posts (or Pages > All Pages, Comments, etc.).

Click on the Trash link to view items in the trash.

Click Empty Trash to permanently delete all items.

Additional Considerations:

Database Backup: Always back up your database before making changes to your WordPress files or using wordpress plugins that alter the database.

Database Optimization: Regularly optimize your database to improve performance, especially if you have a large site.

By following these steps, you can manage how WordPress handles trash, helping to keep your site’s database clean and efficient.

Cut Hosting Costs! Submit Query Today!

Grow With Us

Let’s talk about the future, and make it happen!