WordPress automatically saves versions of your posts so you don’t have to.
Post revisions have been around since WordPress 2.6 and ensure your content is saved periodically do you can revert back to earlier versions of your posts when the unlikely happens, such as power outages or browser crashes.
It’s also a handy feature for writers. If you’re working on an article and regret deleting a passage of text, you can look back over your previous drafts and undo any changes.
In this post, we’ll show you how to use post revisions, how to manage them and how to turn them off.
Using the Post Revisions Editor
When you create a new post in WordPress, the post revisions feature kicks in and stores a record of each saved draft or published update.
You can then access older versions of your posts and compare revisions. To do this, click on Browse in the post editor (as pictured above). You can then see what changes were made in each revision by dragging a slider, or using the Previous and Next buttons (pictured below).
In the example below, you can see that a headline was change and new content was added to the post.
If you’re used to code diff tools, the basic layout of the page here will be familiar with the previous version on the left, newer version on the right, and differences highlighted visually. In addition to viewing the versions, you also have the option of restoring to a previous version entirely.
Along with being able to compare adjacent versions, you can also highlight changes between completely separate versions by ticking the Compare any two revisions checkbox and then use the slider to select the options you’re after.In the example below, we’re comparing versions that aren’t immediately after one another:
In the example below, we’re comparing versions that aren’t immediately after one another:
In terms of actual action items available to you here, the decision is basically to restore or not to restore. The biggest usability gripe you’re likely to run into is that it’s nigh on impossible to easily select and copy text from a particular revision directly from within the comparison view because it will inevitably select text from both posts.
Enabling Global Revisions
If you’re setting up WordPress from scratch, post revisions should be automatically enabled on your site with a default setting of storing every post revision.
If you’re not seeing revisions as an option in your post settings, they’ve almost certainly been switched off at the configuration level. As a first step in working out what’s going on, pop open your wp-config.php file and look for a line like the following:
You’ve got three basic options when it comes to passing a value into
- true or -1: This is the default option in WordPress and makes it store every revision per post.
- false or 0: This removes revisions entirely and limits you to the most recent autosave per post.
- A number greater than zero: This limits your revision count to a specific number and automatically deletes older revisions.
There are two further small items worth pointing out at this stage: you need to set this value above where you define
ABSPATH in your config file, and you also have the option of taking more control over your autosaves with AUTOSAVE_INTERVAL as pictured below.
If you don’t have access to your wp-config.php file, or are still experiencing problems at this stage, you might have to reach out to your hosting provider. As an example, WP Engine disables revisions by default and require that you contact them to enable the option.
Taking Control of Revisions on a Per Post Basis
If you’re comfortable with rolling up your sleeves and doing a little custom coding, you can also take advantage of the wp_revisions_to_keep filter to control how revisions are handled on a per post level.
This is relatively straightforward to implement and simply involves passing in two parameters to the filter – the number of revisions to keep, and a WP_Post object representing the post to be targeted:
Obviously, you’re free to use the body of your function to get at the specific type of post you’re after in any way you like, so long as you are returning a valid object.
Turning Off or Limiting Revisions
While the post revision feature is handy for some, it’s not for everyone, particularly if you are limited database space or simply don’t need to autosave your posts.
To completely switch off post revisions, add the following to your wp-config.php file:
If you want to re-enable revisions, simply set the value to “true.”
Alternatively, if you want to limit the number of revisions of a post, you can use a number. For example:
Adding this line to your wp-config.php file will create a maximum of 10 revisions per post, plus one for auto-saving purpose. Older revisions will be automatically deleted as newer versions are stored.
Risks of Using Revisions on a Live Site
Taken purely as an aid to writers and editors, there’s very little to dislike in the concept of having revisions automatically enabled. The main knock against them comes in the context of performance on a live site.
As each revision is stored as a separate entry in your database, there is a risk you could be unnecessarily hampering your database’s performance on larger sites by having them on.
It’s difficult to give hard and fast indications as to how much of a negative effect this could have on individual sites, but database optimization becomes ever more of a priority as sites grow. With that in mind, let’s move on to some plugins you can use to keep your virtual house in order when it comes to minimizing database impact.
Using Plugins to Clear Out Revisions
Once you’ve gotten your head around the basic concept of revisions in WordPress, you may well find yourself looking to tidy up existing revisions on your site. After a piece is fully through the editorial process, the value of keeping all those revisions hanging around is often dubious at best.
To finish up, we’ll point you in the direction of four handy plugins you can use to clear out revisions once you don’t need them anymore. As with any plugin that can potentially affect your database, make sure you have a fully-functioning backup strategy in place before testing any of these solutions.
The Optimize Database after Deleting Revisions plugin gives you a way of pruning your revisions programatically and keeping database sizes optimized.
The plugin can be called manually or set to run on a schedule, creates its own log files for later analysis, and enables you to choose a number of recent revisions to be excluded while cleaning.
WP-Sweep from Lester Chan performs a wider WordPress housekeeping function, but also enables you to tame your revisions. The plugin is a useful way of tackling issues such as comments, drafts and revisions all in one go when it comes to keeping your site running clean.
As with WP-Sweep, WP-Optimize enables you to trim a lot of fat from your WordPress database and clear up overflowing revisions while you’re at it. You’re free to create custom schedules for when it should run, and the plugin can help you blast through cleaning items such as unwanted draft posts, trashed comments, and much more besides.
Better Delete Revision limits itself solely to cleaning up revisions data, but takes a comprehensive approach and removes all meta information and tags relating to a particular revision while doing so.
With over 60,000 active installs and a consistent star rating of close to five, this plugin comes highly recommended, but it’s worth pointing out that it hasn’t been updated in nearly a year, so proceed carefully if you’re on a recent version of WordPress. You can find a nice breakdown of a typical Better Delete Revision workflow over at Brian Jackson’s blog.
Making the Most of Post Revisions
Post revisions is one of those tools in WordPress you’ll kick yourself for not using previously if you haven’t taken advantage of it to date. Let’s recap the main points to take away when considering using revisions on your site:
- You’re free to set basic parameters for revisions via WP_POST_REVISIONS in wp-config.php.
- You can take more fine-grained programmatic control on individual posts using the wp_revisions_to_keep filter.
- Plugins such as WP-Sweep help minimize database bloat and keep things running smoothly behind the scenes.
Are you currently using revisions as part of your editorial workflow or do you use other tools? Are post revisions essential for your write or a waste of time? Let us know what you think in the comments below.