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.
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.
Love this. Thanks.
woo hoo thanks SJ. nice to see all those revisions gone
Could this speed a site up if it’s taking a while to load?
Yes it potentially could speed up the site… post revisions can bloat the database if there are too many, which can affect site speed.
Thanks.
There is a similarly easy solution. You can put in the wp-config.php the following line:
define(‘WP_POST_REVISIONS’, 5);
Oh wow! added this to functions.php in my child theme. updated my current page which had over 100 revisions and bam back down to the 5 I set.
Nice one SJ!
HI, as above, does it clean up previous posts or just the new ones.
I adds the code as above and it didn’t change the number of revisions – still says 60 on the one page.
brilliant! thanks!
Nice idea. Cheers
Does this function actually clean up the revisions saved prior to the code being put in place? Or just going forward?