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.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *