Disable revisions for a specific post type only?

All we need is an easy explanation of the problem, so here it is.

Any way to disable post revision on specific post types only?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Remove the revisions property inside the supports parameter of register_post_type().

Example

$args = array(
    // ...
    'supports' => array('title','editor','thumbnail','comments','revisions')
); 
register_post_type('book',$args);

Change to:

$args = array(
    // ...
    'supports' => array('title','editor','thumbnail','comments')
); 
register_post_type('book',$args);

Method 2

If you don’t have control over the post type registration, you an use the remove_post_type_support() function:

add_action('admin_init', 'disablew_revisions');
function disable_revisions(){
    remove_post_type_support('post', 'revisions');
}

If you also wish to disable autosave for specific post types, you can do this:

add_action('admin_print_scripts', 'disable_autosave');
function disable_autosave(){
    global $post;
    if(get_post_type($post->ID) === 'post'){
        wp_deregister_script('autosave');
    }
}

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply