How to limit WordPress post/page revisions

Personally, I write my blogs in Google Docs and then move them over to WordPress, but I know some people prefer to write in the WordPress editor directly (who are you??).

I’ve got no problem with that. WordPress is very user-friendly, and that’s literally why the WYSIWYG editor exists, right?

But please, please, please start limiting your drafts. Every time I work on somebody else’s migration I see blogs and pages with 5, 10, even more WP revisions saved. If you don’t limit WordPress revisions, your database ends up looking like a digital hoarder’s garage.

Why you should limit WordPress revisions

Too many post revisions might not sound like a big deal, but here’s why it matters:

Database bloat: every revision is stored as a separate row. Hundreds of posts with multiple revisions = a fat, sluggish database.

Backups get huge: the more junk you’ve got, the bigger and slower your backups.

Hosting limits: if you’re on a smaller plan, wasted storage space literally costs money.

Performance: slow database = slower site. Simple as that.

Most people don’t even realise WordPress saves revisions automatically. That’s why adding a function to limit WordPress revisions is one of the easiest wins you can make for site performance.

The fix: how to limit WordPress revisions with code

Here’s a little chunk of code you can add into your child theme’s functions.php, or pop it into a utility plugin if you prefer:

/**
* Limit revisions to 1 for all post types that support revisions (includes Elementor templates)
*/
function sjwp_limit_revisions( $num, $post ) {
if ( $post instanceof WP_Post && post_type_supports( $post->post_type, 'revisions' ) ) {
return 1;
}
return $num;
}
add_filter( 'wp_revisions_to_keep', 'sjwp_limit_revisions', 10, 2 );

While you’re at it, its not a bad idea to get rid of ones you’ve already saved too…

/**
* Prune older revisions on save so only the latest one is kept
*/
function sjwp_prune_revisions( $post_id, $post, $update ) {
// Safety checks
if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) return;
if ( ! is_admin() || ! $update ) return;
if ( ! post_type_supports( $post->post_type, 'revisions' ) ) return;

$revisions = wp_get_post_revisions( $post_id, [ 'orderby' => 'date', 'order' => 'DESC' ] );
$i = 0;
foreach ( $revisions as $rev ) {
$i++;
if ( $i > 1 ) {
wp_delete_post_revision( $rev->ID );
}
}
}
add_action( 'save_post', 'sjwp_prune_revisions', 10, 3 );

What this code does

Limits WordPress revisions to 1 per post: so only your latest draft is saved.

Deletes older ones automatically: keeps your database lean by pruning on save.

Applies to all post types: posts, pages, Elementor templates, you name it.

All done. You’re good to go without a million revision holding you back.

Limiting WordPress revisions is such a small tweak, but it makes a big difference. Your database stays clean, your backups stay light, and your hosting bill doesn’t creep up because of wasted space.

This site’s still pretty new, so if you found this useful, stick around. I’ll be posting more quick wins to make your WordPress site faster, leaner, and less of a headache.

Leave a Comment

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

Scroll to Top