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 WP-CLI (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 clean up 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.
Still looking for that perfect WordPress host?
- Fully managed
- Secure like Fort Knox
- Free migrations
- Ultimate speed
- Daily backups
- Google Cloud Platform
We recommend using the free WP-Sweep plugin. We don’t recommend the WP-Optimize plugin or Optimize Database after Deleting Revisions plugin, even though they are very popular. They are on our banned list of plugins as they been known to cause serious issues for some Kinsta users.
Download and install the free WP-Sweep plugin. As of writing this, the plugin has over 60,000 active installs with a 4.5 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.
Under “Tools” click into “Sweep.” You will then see revisions, along with the count. You can click on “Details” to see a list of the posts which will be impacted. For performance reasons, only 500 items are shown at a time.
Once you’re ready, click on “Sweep” next to Revisions.
You will then see a short confirmation of the total number of revisions removed. Since this is on a small test site, there aren’t that many. Larger sites will typically have quite a few.
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.