How to limit number of revisions in WordPress

WordPress revisions (previous versions of posts or pages) are very useful. They saved me many times from a mental break. You know, like you write something, and then everything is gone, and the only thing you can do then is scream “NOOOO!”. They are also very useful when collaborating. If several people edit the content and something breaks, you can restore previous version and … know who to blame ;o) But not everyone needs to have dozens or hundreds of revisions stored in database. With many posts database can get really fat from them. Fortunately there is a way to permanently limit them.

Limit Number of Revisions

In order to set the revisions limit, all you need to do is log in to your web server via FTP and add to the wp-config.php file (located in the WordPress root directory), this line:

define( 'WP_POST_REVISIONS', 10 );

This ten means that from now on, WordPress will save a maximum of 10 revisions. If you want more/less, just change this number.

If you want to turn them off, replace the number 10 with “false”, like that:

define( 'WP_POST_REVISIONS', false );

Though, I don’t recommend disabling revisions completely. They really come in handy sometimes.

In order to restore the default behavior (unlimited number of revisions), simply delete the above line of code.

Delete Old Revisions

There is also a possibility to delete older versions of posts or pages without limiting them. All thanks to Optimize Database after Deleting Revisions plugin. The advantage of this solution is that you can keep all revisions while actively working on the post and then run optimization that will remove old revisions based on rules you set.

Optimize Database after Deleting Revisions offers two options that can be used together or separately:

  • remove revisions older than – i.e. you set, lets say, 30 days and when you run the optimization, all revisions older than 30 days counting from today will be deleted. Usually such revisions are unnecessary anyway.
  • keep an ‘x’-amount of the most recent revisions – it works similar to ‘WP_POST_REVISIONS' in wp-config file, but the difference is that unlimited number of revisions will be saved in the database until you run optimization with that plugin.

Plus, with this plugin you will optimize database itself, cleanup some garbage and maybe reduce its size.

4.6 5 votes
Article Rating