You definitely want your website to load faster. Why not lighten your database by limiting or disable altogether WordPress post revisions stored up automatically on your server.
Right from WordPress 2.6 version, WordPress had introduced a feature called ‘Post Revision’. This feature was designed to help store any post you reviewed or edited or in draft form automatically.
You can find the revised version of a post or page at the bottom of WP post editor if the post has been previously edited or previewed.
WP post revision attempt to store each version of edited posts should you want to refer or use any of them in case you discover a mistake or omitted vital information on the published version.
This is absolutely a good idea, if you ask me. But you know there is always the pro and con sides of any product no matter how good and useful.
The con side of WordPress revision is that it has the tendency to fill-up your database quickly thereby reducing your website load speed.
For instance, for every single post you edited 5 times, 4 of that post are stored as revision on your database. Now, if that post consumes 100 kilobyte of data, it implies that 400KB of unwanted data is lying on your database. If you have so many posts you have edited for that number of times, what happens to your database? It would be over loaded with data.
Ordinarily, this should not have been a challenge especially for people who do not edit their blog post multiple times before publishing and does not also edit it after publishing.
But, I bet you edit your post twice or more before hitting the publish button.
Why? Because quality content need to be tweak multiple times in order to have the flow that would resonate with your targeted audience and then add value to them.
Except you’re a rear genius, that’s when you can parade quality content that has not been reviewed more than once or twice. To this end, it is almost not impossible to found ways of limiting your post revisions useful especially if you want your website to load faster and be in the good book of Google for high ranking.
How to limit or disable WordPress post revision
There are multiple options to do this. You can do it either through inserting code manually on your site or by installing WP plugins that can help you achieve the same result.
I’ll walk you through the two major methods.
Code method 1: To limit post revision;
You might choose to limit the number of revision stored on your database if you’d like to refer to them later. All you need to do here is to insert the code below into wp-config.php on your website file.
Please, ensure you do full backup of your site whenever you want to insert code on your website.
define(‘WP_POST_REVISIONS’, 2);
It will limit the number of post revision to ‘2’. You can change this value to suit your need.
To locate wp-config.php file, you’ll have to log in to your web file manager through your cpanel or other website file management softwares like filezilla.
Locate your website files on the root directory.
Go to ‘wp-config.php‘ and click on it to edit.
Insert the above code into it just before the ABSPATH tag.
Refer to the image below for direction.
Click on ‘Save‘ and you’re done.
Code method 2: To disable WordPress post revision;
Insert the code below into wp-config.php. It will disable post revision and you will not see any post revisions on WP post editor page.
define(‘WP_POST_REVISIONS’, false);
Follow the above procedure for inserting the code into wp-config.php.
Code method 3: To delete previously stored post revision;
If you have been blogging for some time, there’s every tendency that your database could have stored so many unwanted post revisions except your website is hosted by WP Engine because this web hosting company automatically optimize your databaseaff.
Inserting the above codes will neither delete nor limit old post revisions that have been stored before you insert the code.
However, if you’re really web savvy, there are queries you can run on PhpMyAdmin that will delete all previously stored revisions.
All you need to do is log in to your PhpMyAdmin and run the SQL query below;
DELETE FROM wp_posts WHERE post_type=’revision’;
The down side of this is that if you have changed your table prefix (which is recommended for security reasons), then the above code will not work until you change the table prefix (wp_) to match with yours.
Alternatively, you may use the global $wpdb query below;
$wpdb->query($wpdb->prepare(“DELETE FROM $wpdb->posts WHERE post_type = %s”, ‘revision’));
There is yet another better option you can explore to get old post revisions deleted.
Other method
Make a file out of the php code below using notepad and name it anything you like (don’t forget to put dot php).
<?php require_once('wp-load.php'); $posts = get_posts('post_type=revision&post_status=any&numberposts=-1'); foreach($posts as $post) { echo "{$post->post_title}n"; wp_delete_post($post->ID,true); } ?>
Courtesy: Mike Schinkel
For me, I named it gem.php
It is also important you change all the table prefix to match yours if you’ve ever changed it as noted on the previous.
Now, dump (upload) this file on your website root directory where you have WordPress files (wp-content, wp-admin, etc).
Open your browser and go to the file.
For example;
yoursiteurl/thefilename.php
For me, it would be;
http://frandytestsite.com/gem.php
This query will delete all the past stored post revisions without leaving any trace behind.
Don’t worry if all the above methods look too much than what you can handle. There are free WordPress plugins that can get the job done without you touching a line of code.
Plugin method
– To delete previously stored post revisions: All you need to do is to install WP plugin called ‘Better Delete Revision‘. After installation, go to ‘Setting‘ on your admin panel. Click on ‘Better Delete Revision‘ and you’ll see two buttons.
One for deleting all the post revisions that have been stored on your database and the other button is used to optimize your database.
So, you’ll need to click on ‘Check Revision Posts’. It will list all the revisions that need to be deleted.
Scroll down to the bottom of the page and click on ‘Yes, I would like to delete them‘ button.
There’s also an option to keep them if that’s what you prefer. But, it’s better to delete them and probably set limit for your future post revisions.
-To limit the number of post revisions: There is another plugin you can use called ‘WP Revisions Limit‘. Install it and then go to ‘Setting‘ on your admin panel and click on the plugin name.
Set the number of post revisions you want to keep on your database and hit the ‘Save changes‘ button.
– To optimize your database: There is a plugin that does much more than mere delete stale post revisions. The plugin is called ‘WP Optimize‘. See below the complete features of the plugin.
Enable/Disable trackbacks for all published post
Enable/Disable comments for all published post
Removal of stale post revisions
Removal of stale unapproved and spam comments
Removal of trashed comments
Removal of akismet metadata from comments
Removal of other stale metadata from comments
Removal of all trackbacks and pingbacks
Cleaning up auto draft posts
Removal of transient options
Clear out the post trash
Automatic cleanup of all the integrated options (also uses retention if enabled)
Ability to keep selected number of weeks data when cleaning up
Option to add or remove link on WP admin bar.
Enable/Disable weekly schedules of optimization
Apply native WordPress MySql optimize commands on your database tables without phpMyAdmin or any manual query.
Display Database table statistics. Shows how much space can be optimized and how much space has been cleared.
This plugin is a ‘must-have’ for webmasters that place premium value on site speed. It’s good for both user experience and SEO technique.
Ensure you backup your files if you’re using it for the first time.
Conclusion: One of the first things to do whenever you want to make your site load faster is to optimize your database. Doing so will purge the site of data that lied fallow which would also be processed whenever requests that is associated with them are made.
One of the contributors of these unwanted data is WordPress post revision tool. It is therefore expedient to either disable it or limit the number of post revisions that can be stored on your website. What do you think?
- How to Add Post Thumbnail Image to RSS Feed on WordPress - February 16, 2016
- 10 Tips for Getting the Most out of Google Image Search - January 19, 2016
- How to Add Next and Previous Post Links with Thumbnail - January 11, 2016