How can one limit the amount of "revisions" that are allowed to go back on pages & pos

Hi folks,

How can one limit the amount of “revisions” that are allowed to go back on pages & posts?

What is the best way to remove automatically all past revisions for pages and posts, say, beyond 25 versions?

:slight_smile:

  • Adam Czajczyk
    • Support Gorilla

    Hey Greg,

    I hope you’re well today and thanks for your question!

    The simplest way to limit number of post/page revisions is to add this line to the wp-config.php file (somwhere above the “/* That’s all, stop editing…” line):

    define( 'WP_POST_REVISIONS', 3 );

    Please replace the number with actual number of revisions you’d like to keep (e.g. 25).

    In case you’d like to set different number of allowed revisions for post and pages, instead of above way, please add the following code to your current theme’s functions.php file:

    add_filter( 'wp_revisions_to_keep', 'my_wp_revisions, 10, 2 );

    function my_wp_revisions( $num, $post ) {

    if( 'post' == $post->post_type ) {
    $num = 6;
    }
    if( 'page' == $post->post_type ) {
    $num = 3;
    }

    return $num;
    }

    Replace numbers (6 and 3) with your own values, of course.

    I hope that helps!

    Cheers,

    Adam