By JOHN HUGHES
Occasionally updating or revising a post on your WordPress site isn’t a time-consuming task. It also doesn’t take up a lot of space. However, over time, revisions do start to add up and can eventually take up a considerable amount of space on your database.
Whether you’re in a pursuit to free up some much-needed space or prevent the matter altogether, disabling or removing old post revisions from your WordPress site is an available option. Doing either can help reduce database bloat and optimize performance.
In this post, we’ll discuss what post revisions are and how they can be used. We’ll explain why you’d want to disable, limit, or remove them, and walk you how to do each one. Let’s get started!
What Is a Post Revision?
Post revisions, which are sometimes referred to as revisions, are a built-in feature of WordPress. They are useful because they make it easy to revert to a previous version of a post and undo the changes you made.
For example, let’s say you decided to delete some paragraphs in your post. However, later, you realize that edit was a mistake and want to recover the information you eliminated. With post revisions, you can easily do that.
In WordPress Gutenberg, this feature is located on the right navigation panel under Document > Revisions:
If you’re still using the Classic Editor, you can find the revisions under the Publish box, also in the right navigation panel:
When you’re viewing revisions, WordPress shows you the new information that was added as well as what was removed through respective highlighting. New changes will be highlighted in green:
There’s also a mode to compare versions of the revisions. When you select the version you want, you can click on the Restore This Version button.
Why Would You Want to Disable, Limit, or Remove WordPress Post Revisions?
With the WordPress revisions system, each update or draft is recorded and gets stored in your WordPress database. While having the option to view the changes made to a post and restore previous versions can be super helpful, it can also take up space.
The more revisions you make, the more bloated your database can get. Database optimization is an important part of WordPress site maintenance. Therefore, managing the revisions on your site is highly recommended. Removing old revisions, for example, can reduce the size of your backups.
There are three main options to choose from for managing post revisions. You can disable them completely, limit how many are allowed, and remove the old post revisions. Below, we’ll cover how to go about each of these, starting with disabling post revisions.
How to Disable Post Revisions in WordPress
One way to prevent an accumulation of revisions from piling up in your WordPress database is to remove the opportunity for them to in the first place. You can do this by disabling post revisions.
In order to disable post revisions permanently, locate your WordPress site’s wp-config.php file that’s located in the root directory. Add the following line of code at the very top:
define( ‘WP_POST_REVISIONS’, false );
This line of code disables post revisions from being saved to your database in the future. If you’d like to enable this option sometime in the future (for whatever reason), simply replace the line with:
define( ‘WP_POST_REVISIONS’, true );
When you’re done, be sure to save your changes before exiting. Completely disabling post revisions isn’t necessarily something we recommend. There are other less drastic options you can pursue to optimize and manage revisions in your database. However, if you do want to do it, it helps to know that option is there and can easily be activated or deactivated when necessary.
How to Limit Post Revisions in WordPress
If you’re like most people, you’ll want to save a couple of post revisions for every post you add to your site – just to be on the safe side. For this, the best option is to set a limit on the number of post revisions that are saved to your database.
You can do that by adding the following line to your wp-config.php file:
define( ‘WP_POST_REVISIONS’, 3 );
This line saves the three most recent post revisions instead of all of them, meaning the older ones are automatically deleted once newer versions are saved. You can replace the number three with another integer depending on your preference.
Instead of limiting the post revisions to a pre-defined number, you can also increase the auto-save interval to save fewer revisions. To do this, open up your site’s wp-config.php file and add the following line at the top:
define( ‘AUTOSAVE_INTERVAL’, 600 );
By default, WordPress auto-saves your post revisions every minute (60 seconds). However, by adding this line it will save them every 10 minutes (600 seconds). This automatically reduces the number of post revisions that are stored in the database.
If you shy away from coding or adding code to your site’s wp-config.php file, you can always get the job done by installing a plugin, such as WP Revisions Control. After you install and activate this plugin, you can configure that number of post revisions allowed by going to Settings > Writing:
It’s important that you understand that the techniques we covered so far disable or limit post revisions from being saved for future posts. What about the past revisions?
How To Remove Old Post Revisions In WordPress (2 Methods)
In this section, we’ll cover the two methods you can use to permanently remove old post revisions from your WordPress site’s database. If you’re familiar (and comfortable) with SQL queries, you can go with the first method. However, if you’d prefer using a plugin then go ahead and skip right down to the second method.
Method 1: Deleting Post Revisions Using Code
Deleting post revisions from your database is one of those things that you should be able to do without having to install a plugin (although there are plugins for it too, which we’ll cover next). After all, you’re trying to save space and installing a plugin generally goes against that.
In order to delete all of your past post revisions from your site’s database, login to the cPanel of WordPress site’s hosting account and click on the phpMyAdmin icon.
In the left navigation panel, find and click on your WordPress database. Click on the SQL tab:
You’ll be brought to the phpMyAdmin SQL interface. Next, where you can run an SQL query. You can do this by entering the following snippet of code:
DELETE FROM wp_posts WHERE post_type = "revision";
Make sure to replace wp_ with your own WordPress database prefix. Then click on the Go button. This will initiate the command:
This SQL query removes all posts from your database that have post_type = “revision”. You might want to create a backup of your database prior to running this query as an added security measure. In our opinion, it’s always best to make backups of your database before you make drastic changes to it.
Method 2: Use a WordPress Plugin to Delete Old Post Revisions
Although deleting post revisions from your WordPress site can be accomplished by running a single SQL query, you might find it easier to install a plugin and let it do all the work. This might be because the plugin has added benefits (database maintenance, removes excess files etc.) or simply because you’re not comfortable with programming.
Whatever the reason, there are a variety of plugins you can use to delete old post revisions. One you might consider using is WP-Optimize:
Although this plugin offers a premium version with advanced features, you can download it and use it to delete old revisions for free. WP-Optimize is an all-in-one plugin that you can use to optimize your WordPress database. In addition to using it to delete revisions, you can also use it for important maintenance tasks such as image compressing and caching.
Once you install and activate the plugin, it will add a WP-Optimize menu item to your WordPress dashboard. To delete post revisions, you can navigate to WP-Optimize > Database.
Under Optimizations, you can check the box next to ‘Clean all post revisions’, then click on the Run Optimization button:
You can delete the plugin or deactivate it once you’re finished with this process. That way, you don’t have to worry about it taking up any unnecessary space in your WordPress database.
Wrapping It Up
Post revisions don’t slow your site down or threaten the User Experience (UX). They do, however, start to take up a lot of space on your site’s database over time. Fortunately, limiting or removing old post revisions will clear up a significant amount of space on your database.
As we discussed in this post, there are two methods you can use to disable, limit, or remove old post revisions from your WordPress site:
- Manually deleting and disabling post revisions from your site’s code.
- Installing plugins such as WP Revisions Control and WP-Optimize.
Which method are you most comfortable with for disabling/removing old post revisions? Is there another method you use? Let us know in the comments section below!
Reference: https://www.wpkube.com/how-to-disable-post-revisions-in-wordpress/