i want to be able to set the revisions limit number of a specific post type. i know there is a plugin for that, and i know it can be set through the "wp-config.php" file, but my question is:

Is there a simple short code i can implement on my theme to do that without a plugin and without the need to change other files out of the theme folder scope?

1 Answer 1


I had a look at the wp_revisions_to_keep() function. There's a filter called wp_revisions_to_keep that overrides the value of WP_POST_REVISIONS.

Here's an untested example (PHP 5.4+):

add_filter( 'wp_revisions_to_keep', function( $num, $post )
    // Post Types and Revision Numbers - Edit to your needs
    $config = [
        'post' => 10,
        'page' => 9,
        'cpt'  => 8

    // Get the current post type
    $post_type = get_post_type( $post );

    // Override the WP_POST_REVISIONS value
    if( isset( $config[$post_type] ) && is_int( $config[$post_type] ) )
        $num = $config[$post_type];

    return $num;
}, 10, 2 );

But I think this kind of configuration would make more sense as a plugin than being theme related.

  • IIRC it is 5.3+ ;) Commented Sep 29, 2016 at 12:14
  • I'm a sucker for the [] array syntax notation ;-) I thought that was 5.4+ @MarkKaplun
    – birgire
    Commented Sep 29, 2016 at 12:42
  • Oh, that syntax.... no idea since when it is Commented Sep 29, 2016 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.