WordPress Managed Hosting - 40% Off For 4 Months - Coupon Code: BFCM2021 Avail Now

How to Disable and Limit WordPress Post Revisions

Moeez — March 28, 2017 4 Minutes Read

There is nothing worse than a slow website!

WordPress powered websites often slow down overtime because of a number of reasons. An important reason is the number of post revisions that add to the clutter that bogs down the website.

How to Disable WordPress Post Revisions

  • Disable WordPress Post Revision
  • Revision Control for Posts
  • Revision Control Cleanup Through SQL Query
  • Options To Pass Value of Post Revisions
  • An Alternative

Post revisions are a great WordPress feature, but not for users with limited database space, or for users who simply do not need the autosave feature for their website.  For all these users, simply disabling the Post revisions feature in the WordPress is the best option.

In the following steps, I will demonstrate how you could easily turn off WordPress Post revisions. I will also discuss an alternate option for limiting limit post revisions.

First of all, create a backup copy of wp-config.php file (commonly located at the root of the WordPress website folder structure) to a safe location. In case of anything going wrong, this backup will ensure that your website returns to normal.

Disable WordPress Post Revision 

Open wp-config.php in your code editor. I will add the following code snippet.

Notice that in the first line, I have changed the default autosave interval.

Note: This code snippet must be inserted above ‘ABSPATH’. Otherwise,  it won’t work.

Whenever you make a change in a post, WordPress automatically saves a new version. Even for a mid-sized blog, these versions increase the size of the database. WordPress has a built-in revisions control option that could be set in the wp-config.php file. You can even disable the revisions altogether!

Revision Control for Posts

You need to write custom code for controlling the number of revisions for individual posts. The code is simple and involves passing on two parameters to the filter, the number of revisions to retain, and wp_post object representing the post to be targeted:

Revision Control Cleanup Through SQL Query

One problem with the above code is that it will not delete the past revisions that are already saved in the database. To delete all previous revisions, go to PHPMyAdmin and run the following SQL query.

Options To Pass Value of Post Revisions

If you are setting up WordPress from the scratch, post revisions should be automatically enabled on the website, with a default setting of storing every post revision.

If you do not see revisions as an option in the post settings, they are, almost certainly, been switched off at the configuration level.So, as the first step in working out what’s going on, open up the wp-config.php file in the code editor and look for a line like the following:

When it comes to passing a value to WP_POST_REVISIONS, you have got three basic options:

  1. true or -1: This is the default option in WordPress and it stores every revision per post.
  2. false or 0: This removes revisions entirely and limits you to the most recent autosave per post.
  3. A number greater than zero: This limits your revision count to a specific number and automatically deletes older revisions.

Save the wp-config.php file and re-upload it to your server. And you are done! The revisions option next to the Publish button is no longer visible.

An Alternative

Alternatively, if you want to limit the number of revisions of a post, you can use a number. A common scenario is when the clients need WordPress revisions, while the developers wish to reduce the strain on the database. In such cases, the developers set a number of revisions to be retained. WordPress will automatically limit the number of saved post revisions to the selected number.

Check out the following code snippet:

The above code will save only three WordPress revisions. This is important because WordPress Posts could often save hundreds of revisions or a single posts. To view a particular revision, click Browse.

Conclusion

In this tutorial, I have covered how to limit post revision by defining the code in the configuration file. The WordPress revisions system stores a record of each saved draft or published update. If you need help with post revisions control, do leave a comment below.

Create Faster WordPress Websites!

Free eBook on WordPress Performance right in your inbox.


    Create Faster WordPress Websites!

    Free eBook on WordPress Performance right in your inbox.

      Moeez is ‘The’ blogger in charge of WPblog. He loves to interact and learn about WordPress with people in the WordPress community. Outside his work life, Moeez spends time hanging out with his friends, playing Xbox and watching football on the weekends. You can get in touch with him at moeez[at]wpblog.com.

      THERE'S MORE TO READ

      Newsletter

        WordPress Help Zone - Ultimate WordPress Pit-Stop

        Learning WordPress? Or are you expert enough to help others? Join our WP Facebook group!