By default, WordPress keeps trashed items for 30 days before permanently deleting them. While this feature can be useful if you accidentally remove content, it may affect your website’s performance, especially if you are running an eCommerce store, a blog with thousands of posts, or a business website. In this guide, we’ll explain how to delete trash in WordPress automatically, why it’s important, and the best methods to keep your site optimized.
When you manage a WordPress website, you might often delete posts, pages, comments, or media files. But did you know these items don’t disappear right away? Instead, they are moved into the Trash folder. Over time, this stored data can slow down your site and take up unnecessary database space. That’s why it’s essential to learn how to delete trash in WordPress automatically.
Why Should You Delete Trash in WordPress Automatically?
Every extra piece of data in your WordPress database impacts performance. Let’s look at the key reasons:
- Improved Website Speed – A lighter database means faster queries and a quicker website.
- Better SEO Rankings – Search engines favor websites with fast load times.
- Reduced Database Size – Helps prevent hosting storage from being filled with junk files.
- Cleaner User Experience – Avoids clutter in your WordPress dashboard.
👉 If you are running your site on shared hosting or WordPress hosting, regularly cleaning trash is even more important. At Hostrago, we always recommend database optimization as part of site maintenance.
How to Change Trash Deletion Settings in WordPress
WordPress has a built-in function that allows you to control how long trashed items stay before deletion. This can be done by editing the wp-config.php
file.
Here’s how:
- Access Your WordPress Files
- Use cPanel’s File Manager or an FTP client to open your website files.
- Locate wp-config.php
- Find the
wp-config.php
file in your WordPress root directory.
- Find the
- Add the Code
- Insert the following line before the “That’s all, stop editing!” comment:
define('EMPTY_TRASH_DAYS', 7);
In this example, trashed items will be deleted automatically every 7 days instead of the default 30. - Set to Zero for Instant Deletion
- If you want items to skip the Trash folder and be deleted immediately, set the value to
0
:
define('EMPTY_TRASH_DAYS', 0);
- If you want items to skip the Trash folder and be deleted immediately, set the value to
Automating Trash Deletion with a Plugin
If you’re not comfortable editing files, you can use a plugin. Several WordPress plugins help you optimize and delete trash automatically:
- WP-Optimize – Cleans your database and removes unnecessary junk.
- Advanced Database Cleaner – Offers scheduling for automatic trash deletion.
- WP-Sweep – Deletes revisions, trash, spam comments, and more.
Best Practices to Keep WordPress Database Clean
- Regular Backups: Always back up your site before making changes. You can use plugins like UpdraftPlus or Jetpack Backup.
- Use Reliable Hosting: Hosting plays a huge role in performance. At Hostrago, our optimized WordPress hosting ensures faster speeds and better resource handling.
- Monitor Performance: Use tools like Google PageSpeed Insights or GTMetrix to check site health.
- Limit Post Revisions: Add a line in your wp-config.php file to reduce stored revisions. Example:
define('WP_POST_REVISIONS', 5);
Final Thoughts
Learning how to delete trash in WordPress automatically is a small but powerful step in optimizing your website. A clean database improves speed, SEO, and overall performance, which directly benefits your visitors and business. Whether you prefer using the wp-config.php
method or a plugin, the key is to ensure that your trash is regularly emptied without manual effort.
At Hostrago, we provide high-performance WordPress hosting with tools that make database management easier, so you can focus on growing your website while we handle the technical side.
If you want to explore more tutorials, check out our Knowledge Base for guides on WordPress optimization, security, and hosting tips.