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.

  • Google+
  • Facebook
  • Twitter

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.

Previous post
Next post


  1. Sandy

    Does this function actually clean up the revisions saved prior to the code being put in place? Or just going forward?

  2. Colin

    Nice idea. Cheers

  3. ben

    brilliant! thanks!

  4. Quintin

    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.

  5. John Anderson

    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!

  6. Fecsó

    There is a similarly easy solution. You can put in the wp-config.php the following line:

    define(‘WP_POST_REVISIONS’, 5);

  7. Wayne

    Could this speed a site up if it’s taking a while to load?

    • Cory Jenkins

      Yes it potentially could speed up the site… post revisions can bloat the database if there are too many, which can affect site speed.

  8. Leisa

    woo hoo thanks SJ. nice to see all those revisions gone

  9. Karen

    Love this. Thanks.


Submit a Comment

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

Receive notifications about our new blog posts.