How to Optimize WordPress Revisions for Faster Performance

Updated on July 22, 2018

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

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.

Running any type of database plugin could break your site if not done correctly. We always recommend backing up your MySQL database beforehand. If you are not comfortable doing this, please check with a developer first.

Step 1

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.

optimize database after deleting revisions

Optimize Database after Deleting Revisions plugin

Step 2

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.”

delete revisions in wordpress

Delete revisions in WordPress

Step 3

Then click on “Start Optimization.”

start optimization database

Start optimization of database

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.

revisions deleted

Revisions deleted

We then suggest uninstalling the database optimization plugin and following the next recommendation on limiting post revisions further below.

Delete WordPress Revisions With WP-CLI

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)
wp-cli delete wordpress revisions

WP-CLI delete WordPress revisions

You can read more about the wp post delete command in the WP-CLI documentation.

Limit Number of WordPress Revisions

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.

Step 1

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.

Important! Editing the source code of a WordPress theme could break your site if not done correctly. If you are not comfortable doing this, please check with a developer first.

Step 2

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.

define('WP_POST_REVISIONS', 3);

It should look something like the following.

wp post revisions

WordPress post revisions

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.

Limit post revisions with perfmatters plugin

Limit post revisions with perfmatters plugin

Disable WordPress Revisions (Optional)

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.

Step 1

The steps are the same as limiting revisions above. Open your wp-config.php file.

Step 2

The code below needs to be inserted above the ‘ABSPATH’ otherwise it won’t work.

define('WP_POST_REVISIONS', false);

It should look something like the following.

disable wordpress revisions

Disable WordPress revisions

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.

disable post revisions

Disable post revisions

Was this article helpful?
No, or there was something off

Hand-picked related articles

Use WordPress?

Use WordPress?

Join 20,000+ others who get our FREE weekly newsletter with WordPress tips on how to drive more traffic and revenue to your business!


You have Successfully Subscribed!

Send this to a friend