WordPress has a handy post revision feature which saves earlier states of a post as you make edits. Not everyone wants or needs this feature, however, and it’s handy to be able to turn it off. Plugins exist for this, but I prefer code solutions that I can put in my themes or site-specific plugins. Here’s a simple method to disable post revisions without installing a plugin:
/**
* Disable revisions for all post types.
*/
function my_disable_post_revisions() {
foreach ( get_post_types() as $post_type ) {
remove_post_type_support( $post_type, 'revisions' );
}
}
add_action( 'init', 'my_disable_post_revisions', 999 );
If you’d like to disable post revisions for only specific set of built-in or custom post types instead of targeting all types, you can do that with an array:
/**
* Disable revisions for all post types.
*/
function my_disable_post_revisions() {
$types = array( 'post', 'my-custom-type' );
foreach ( $types as $post_type ) {
remove_post_type_support( $post_type, 'revisions' );
}
}
add_action( 'init', 'my_disable_post_revisions', 999 );
The high priority, 999
, means it’s almost certain to execute after any other code which adds revision support.
The ability to disable revisions is particularly helpful when moving a site from another system to WordPress. Frequent post editing and other operations may result in a large number of revisions saved in the database.
If you want to start saving revisions again, simply remove this code from your theme or plugin.