Limit the number of post/page versions stored in the database without a plugin

Limit the number of post/page versions stored in the database without a plugin

True story: If you use a page builder powered theme like Divi then you have way too many versions of the same pages and posts stored in your database. Every time you update the page and check how it looks, you’re saving a version of that post or page to your site and in doing so, pushing the size up and up and up. Though the new front end builder in Divi 3.0 is sure to save you the need to push the update button as often, this can still be a problem.

version-control

Though there are several plugins that handle the number of versions saved, if that’s all you’re trying to do then you might find them a little bloated. Luckily there’s a simple filter called ‘wp_revisions_to_keep‘ which makes it easy to limit the maximum number of revisions  on any post or page.

If you want to limit the number of revisions being kept in the database in your Divi install then add this to your child theme’s functions.php:

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

function divi_limit_revisions( $num ) { 
 $num = 3;
 return $num;
}

Be sure to drop it in between the opening and closing ( <?php … ?> ) tags. If you haven’t got a child theme, you can grab one here. This limits the number of revisions to three, but you can change that number to anything you want.

I hope you find this useful.

Stephen James

SJ is a web developer living in the coastal town of Southsea, England. He is a Divi and WordPress advocate and the founder of Divi Space.