Whenever you save a page or post in WordPress it creates a revision. This occurs in both drafts and already published posts that are updated. Revisions can be helpful in case you need to revert back to a previous version of your content. However, they can also hurt the performance of your WordPress site. On large sites this can add up very quickly to thousands of rows in your database which are not necessarily needed. And the more rows you have the larger your database in size, which takes up storage space. Follow the steps below on how to delete, limit, and disable WordPress revisions for faster performance.
Optimize WordPress Revisions
It is not uncommon for older sites to have 100+ revisions on their main pages. This is simply due to years of editing and updating content. Let’s say for example a site has 700 pages or posts with 150 revisions on each, this would be over 100,000 entries in the database. This happens a lot more frequently than you might think. Thankfully, there are a couple easy optimizations you can make to ensure this doesn’t hurt the performance of your site.
- Delete WordPress Revisions With Plugin (Easy)
- Delete WordPress Revisions With Plugin (Advanced)
- Limit Number of WordPress Revisions (Recommended)
- Disable WordPress Revisions (Optional)
If you are starting a new site, you can skip to the next section as you won’t have existing revisions. If you are on an older site, the first thing you will probably want to do is cleanup and delete the hundreds or thousands of WordPress revisions. This is where a lot of the magic happens, and you can free up space in your database. If you are trying to do this with a MySQL query, be very careful as there are a lot of bad snippets of code floating around the WordPress repository forums with bad information. Many suggest queries that sometimes delete a relationship needed to make dashboard links work.
We recommend using the free Optimize Database after Deleting Revisions plugin. It uses the built-in WordPress term functions, which is the correct way to do things. We don’t recommend the WP Optimize plugin, even though it is very popular. It is on our banned list of plugins as it has been known to cause issues for some Kinsta users.
Download and install the free Optimize Database after Deleting Revisions plugin. As of writing this, the plugin has over 90,000 active installs with a 4.8 out of 5 rating. You can download it from the WordPress repository or by searching for it within your WordPress dashboard under “Add New” plugins.
Click into the plugin settings of “Optimize Database” and input the date of the time for which you want to delete revisions. In our example we did any revisions that are older than 1 day. Below, select the “check all tables,” which will exclude them from being optimized. We are not wanting to do anything else in this tutorial other than delete revisions, we will dive into optimization in another tutorial. Scroll down and click on “Go to Optimizer.”
Then click on “Start Optimization.”
You will then see a summary of the space saved and the deleted revisions. Since this is on a small test site, you can see we only saved 16 KB. But it will be much more for larger sites.
We then suggest uninstalling the database optimization plugin and following the next recommendation on limiting post revisions further below.
Another option, especially one that WordPress developers might like, is the ability to delete post revisions with WP-CLI. Here is an example of a WP-CLI command:
$ wp post delete $(wp post list --post_type='revision' --format=ids)
You can read more about the wp post delete command in the WP-CLI documentation.
After you have cleaned up your old revisions, the next step is to limit the number of WordPress revisions that you allow. This can be a great stop gap measure to ensure that the revisions don’t pile up again. Perhaps you want to save 3 revisions. WordPress will keep that number and delete any previous ones. You can also use wp-revisions-cli to cleanup post revisions based on the number you set below.
Open your wp-config.php file. You will need to add some code. This is typically located in the root of your WordPress site directory and you can access it via FTP.
The code below needs to be inserted above the ‘ABSPATH’ otherwise it won’t work. Again, you can change the number to however many of revisions you want to keep stored in your database per page or post.
It should look something like the following.
Alternatively, you can also use a premium plugin like perfmatters (developed by a team member at Kinsta), which allows you to limit the number of stored WordPress revisions or disable them altogether.
The last option you have is to simply disable WordPress revisions altogether. Typically option 2 above is the most commonly used method. However, if you are on a single author site, you might simply want to get rid of them altogether. Remember, it will still save a draft, it just won’t have revision restore points.
The steps are the same as limiting revisions above. Open your wp-config.php file.
The code below needs to be inserted above the ‘ABSPATH’ otherwise it won’t work.
It should look something like the following.
Alternatively you could also use a free and lightweight WordPress plugin called Disable Post Revision. Simply install it, click into “Writing” in your dashboard, and select the post types for which you want to disable revisions.