Limit the number of stored revisions per post in WordPress

It’s been a while since WordPress implemented revisions for posts and pages. Being able to revert a post or page to a previous state is a useful feature. However, I recently realized that WP creates a revision of the content every time it is saved, but there is no upper limit for the number of stored revisions. So, if you save your work quite often, it is very possible that the WordPress database is filled with numerous revisions of the content, which make the database grow in size quite aggressively. After thinking about it for a while, I realized that all those revisions are pretty useless to me. All I really care about is having a couple of recent revisions of each post or page available, so as to be able to get an idea of my recent changes.

It was only a matter of minutes to find out that it is possible to limit the number of stored revisions per post in WordPress. Open wp-config.php in your favorite editor and add the following:

 * Revision management. Store 5 (+1 autosave) revisions per post.
define('WP_POST_REVISIONS', 5);

The above setting forces WordPress to store only the 5 most recent revisions of the content. One extra revision is also saved because of the autosave feature.

The acceptable values for WP_POST_REVISIONS and their meanings are:

  • -1: store every revision (this is the default)
  • 0: do not store any revisions except for the one used for the autosave feature
  • N (integer) > 0: store N revisions per post. Revisions are rotated so that only the N most recent recent ones are available.

After getting rid of all those useless revisions that had piled up over the last months, I’m now quite happy with the size of the database. Although the idea of automatic revisions is fine, in my case, on-demand revisions would have been more useful and would make more sense in the way I author these posts.

Limit the number of stored revisions per post in WordPress by George Notaras is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Permissions beyond the scope of this license may be available at Licensing Information.
Copyright © 2012 - Some Rights Reserved

George Notaras avatar

About George Notaras

George Notaras is the editor of G-Loaded Journal, a technical blog about Free and Open-Source Software. George, among other things, is an enthusiast self-taught GNU/Linux system administrator. He has created this web site to share the IT knowledge and experience he has gained over the years with other people. George primarily uses CentOS and Fedora. He has also developed some open-source software projects in his spare time.