How to Disable and Limit WordPress Post Revisions?

Revisions in WordPress exist for a long time. They allow you to save a backup copy of a record or a page with each change, and then to view all versions with the ability to restore any of them. Despite this useful functionality, each revision is actually a copy of the record itself, which is also stored in the database. On large websites with lots of content, revisions can significantly increase the size of the MySQL database.

In this brief article we will discuss several methods of the maximum number of revisions for each record limitation, as well as of removal of all the revisions of the WordPress database.

Restriction On Number of Revisions

By default, WordPress stores all revisions for records and pages. It can be easily changed using wp_revisions_to_keep filter in your plugin, or via wp_post_revisions constant in the configuration file wp-config.php. For example, if we need to save only the last 5 versions of records and pages our plugin will look as follows:

function my_revisions_to_keep( $revisions ) {
return 5;
add_filter( 'wp_revisions_to_keep', 'my_revisions_to_keep' );

By means of the filter, you can also limit editions depending on the type of records. For example, if we need 10 revisions for pages and only 5 revisions for records (and other types), our plugin is as follows:

function my_revisions_to_keep( $revisions, $post ) {
 if ( 'page' == $post->post_type )
 return 10;
 return 5;
add_filter( 'wp_revisions_to_keep', 'my_revisions_to_keep', 10, 2 );

You can also set a limit using wp_post_revisions directive in the configuration file WordPress wp-config.php, however it will be impossible to divide into types of records using this method:

define( 'wp_post_revisions', 5 );

How to Disable Revisions?

By means of the same methods you can remove revisions in WordPress. To do this, you must set a zero limit:

function my_revisions_to_keep( $revisions ) {
 return 0;
add_filter( 'wp_revisions_to_keep', 'my_revisions_to_keep' );

Or using the wp-config.php file:

define( 'wp_post_revisions', 0 );

Please note that making the revisions disabled will not affect the existing revisions. All revisions that existed before the shutdown will remain available, but new revisions will not be created while maintaining. It should also be noted that autosave in WordPress is also a kind of revision, and the methods described above do not turn it off.

RELATED:  How to Include jQuery from CDN for WordPress?

Article last updated on November 22, 2020

Leave a Comment