WordPress, by default, saves copies of each edit you make to a post or page – allowing the possibility of reverting to a previous version of that post or page. This functionality is great if your computer crashes in the middle of writing a new post, or if you inadvertently deleted some key paragraphs.
In WordPress, if ‘Revisions’ is ticked in the Screen Options menu, you can see all the saved WordPress revisions listed at the bottom of each post or page.
These are stored in your WordPress database. If you’re as ‘Save’ happy as me you will find quite a few of them saved for each post – and they can quickly build up to bloat your WordPress database. Once you have published a final version of a post, it is very unlikely you need to keep previous versions of it – but they are still there, cluttering up the database (in the wp_posts table).
Apart from performance gains, having as small a database as possible makes it quicker to backup or restore if required. Fortunately there are ways to delete saved WordPress revisions from the database without impacting your published posts and pages – this will slim your database right back down to a more reasonable size.
Warning: Always backup your WordPress database before editing it in case of database corruption/loss.
Delete WordPress Revisions Automatically – Advanced (but recommended)
- Login to your phpMyAdmin (if using Cpanel it may be found in the Databases section)
- Select your WordPress database
- Click the SQL button to open the SQL command window where you can run SQL queries
- Paste the following SQL command into the SQL window: DELETE FROM wp_posts WHERE post_type = “revision”;
- Click Go to run the command – it may take a few minutes to complete depending on the size of your database
The command deletes all saved WordPress revisions from the posts table in your database – in my test on a small WordPress site it slimmed down the database from 11MB to 3MB – over 70% decrease in size!
Delete WordPress Revisions Manually – Easy (but time consuming)
The ‘Revision Control’ plugin available here includes the ability to delete specific WordPress saved revisions directly via the Revisions meta box in WordPress – but if you have hundreds to delete it will take a long time to manually select and delete each one…
Disable Or Restrict Future WordPress Revisions
Even though you have now removed all the previous ones, new ones will start to build up again in future. To prevent this, just repeat one of the above steps on a regular basis – or you can choose to disable or restrict future revisions:
The easiest way to disable or restrict them in future is to use the ‘Revision Control’ plugin (see ‘delete old revisions manually’ above): “The plugin allows the user to set a site-global setting (Settings -> Revisions) for pages/posts to enable/disable/limit the number of revisions which are saved for the page/post. The user may change this setting on a per-page/post basis from the Revisions Meta box“.
Alternatively, if you don’t want to use a plugin, use the advanced method:
- To disable post revisions completely, add the following line to your wp-config.php file:
define(‘WP_POST_REVISIONS’, false );
- To limit how many revisions WordPress can save e.g. to 2, add the following line to your wp-config.php file (you can change the number to whatever maximum revision count you want):
Of course, revisions are effectively a type of backup whilst you are writing a new post so I would recommend just deleting them every so often from published posts (or restrict them to just 2 or 3) rather than disabling them completely on all future draft posts or you might lose changes to a draft in the event of a power cut or error etc.