Getting rid of Post Revisions in WordPress

Post revisions aren’t a new feature in WordPress. Infact, I think they were released back in version 2.6 for the first time. The interface for interacting with your revisions was then drastically changed in 3.6. I never really payed much attention to the revisions until then. Now post revisions are a very visually prominent element within the edit post screens.


What are post revisions

WordPress automatically saves creates revisions of your content – auto saving every minute by default and whenever you save a post or a page. This is great if you ever need to revert back to a previous edit. If you are familiar with the concept of version control this should be an easy feature to understand. Especially with the nice new UI that allows you to scrub ‘back in time’ through your revisions.


There is only ever a maximum of one autosave for any given post. New autosaves overwrite old autosaves. This means that no, your tables do not grow by one row every 60 seconds. In multi-user settings, one autosave is stored for each user. Autosaves are enabled for all posts and pages but do not overwrite published content. Autosaves are stored as a special type of revision; they do not overwrite the actual post. In fact, whether your power goes out, your browser crashes, or you lose your internet connection, when you go back to edit that post, WP will toss up a warning telling you that has a backup of your post and a link to restore the backup. When reviewing revisions, autosaves are clearly marked.

What to be aware of

Older revisions are never deleted so you always have a full history of all page changes. Every revision creates a new row in WordPress’s posts table as well as multiple entries in the postmeta and term_relationships tables. This can increase the size of your mySQL database and potentially slow down your site for users as well as decrease performance in the dashboard when editing your site.

My thoughts on disabling post revisions

There have been a few rare occasions where post revisions have come in handy. I like the idea of bringing version control into the writing workflow. I definitely appreciate this feature in basecamp text documents. However, in WordPress it seems to create unnecessary database clutter and bloat. Especially on highly trafficked sites and sites with numerous iterations of each post. These days I’m very concerned with speed and performance for the sites that I work on, and you should be too.

Prevent revisions from being stored

One approach would be to prevent WordPress from storing revisions. This can be acheived by placing the following code at the bottom of your wp-config.php file. All of my WP projects are version controlled with git and I typically exclude the wp-config file in my .gitignore file. If you do this make sure to make this edit to your config file on local and any other environments.

define('WP_POST_REVISIONS', false);

Limit the number of revisions stored

Not quite ready or willing to give up on post formats? Then you can set a limit of how many revisions to save by using:

define('WP_POST_REVISIONS', 5);

This will create a maximum of 5 revisions per post, plus one for auto-saving purposes. Older revisions will be automatically deleted.

Removing old revisions

Using the first method of disabling revisions does not delete all of you existing entries from the database so you may want to manually remove them from your database with a little sql statement. It is always a good idea to backup your database before attempting use sql commands.

To delete all revisions for all pages and posts run the following SQL statement:

DELETE a,b,c FROM wp_posts a  LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)  LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)  WHERE a.post_type = 'revision';

You could remove all revisions prior to a specific date, e.g. the following statement will remove all revisions except for those made after January 1, 2010:

DELETE a,b,cFROM wp_posts a  LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)  LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)  WHERE a.post_type = 'revision'AND a.post_date < '2010-01-01';

(Note that MySQL dates are specified using YYYY-MM-DD notation.)

WordPress plugins

I prefer to manage these types of tasks myself instead of relying on plugins, but if that is more your cup of tea, you can search the WordPress plugin director for WordPress plugins offering revision control