Guide to Closing, Deleting, and Limiting Revisions in WordPress

For posts and pages in WordPress revisions The feature stores previous versions of every change you make. While this can be useful when creating content, it can sometimes be tedious and harmful. For example, if you make ten changes to a post or page, 10 old revisions will accumulate in your database. As your site's content and changes increase, this can cause your database to bloat and slow down your site. In this article, I'll explain step-by-step how to disable, limit, and delete WordPress revisions. I've optimized my database using these methods on my own projects and seen improved performance. Let's get started!

Closing Revisions

To disable revisions completely, simply add a line of code to your wp-config.php file. This will prevent WordPress from creating new revisions.

What you need to doOpen the wp-config.php file and add the following code: Add between tags:

define('WP_POST_REVISIONS', false);

When I used this code on a blog site, I prevented unnecessary revisions from accumulating and kept the database size under control. However, be sure to back up your revisions before closing them, as you may need access to older versions.

Limiting Revisions

Instead of turning off revisions completely, you can limit the number of revisions to be kept. This allows you to both preserve change history and keep your database clean.

What you need to doAdd the following code to your wp-config.php file. The number specified in the code represents the number of revisions to be kept. In the example, this limit is set to 3, but you can specify any number you want.

define('WP_POST_REVISIONS', 3);

I used this method on a news site to limit the number of revisions to 5. This maintained editing flexibility and prevented the database from growing unnecessarily.

Deleting Revisions

There's a simple way to purge existing revisions from your database. While many people prefer to do this with plugins, I find it more efficient to keep plugin usage to a minimum. Fewer plugins in WordPress means fewer security vulnerabilities and better performance.

To delete revisions, you can use the following SQL query. You can run this query via phpMyAdmin or another database management tool.

SQL Query:

DELETE a, b, c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision';

WarningIf your table prefix is different from the default wp_ (for example, xyz_), replace wp_ with your own prefix in the query. For example, xyz_posts, xyz_term_relationships, etc.

When I ran this query on a client site, I cleared out hundreds of old revisions and significantly reduced the database size. There was a noticeable improvement in site speed!

Additional Tips

  • Get Backups: Back up your database before deleting or closing revisions. This way, you don't accidentally lose any important data.
  • Plugin AlternativeIf you don't want to mess with SQL, you can use reliable plugins like "WP-Optimize" or "Delete All Revisions", but be careful and download plugins only from official sources.
  • Regular CleaningIf you are working on a large site, you can set up a cron job to clean up revisions regularly.

Conclusion

Managing revisions in WordPress is an important step in improving your site's performance and keeping your database clean. You can optimize your site by using the methods above to disable, limit, or delete revisions. When I've applied these techniques in my own projects, I've both increased site speed and prevented unnecessary data accumulation. Make your WordPress site more efficient with these simple steps!

5 1 vote
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments