Type something to search...
How to Limit Post Revisions in WordPress?

How to Limit Post Revisions in WordPress?

WordPress saves a new revision every time you update a post or page, and by default, it keeps every single one, forever, with no limit at all. A post you've edited fifty times over the years has fifty extra rows sitting in your wp_posts table, each a full copy of that post's content at the time it was saved. On a frequently-edited site, this adds up to a meaningful share of your total database size without providing much practical value beyond the last few versions.

The fix is a single constant in wp-config.php, and this guide covers exactly how to set it, what the tradeoffs are between capping revisions and disabling them entirely, how to apply a limit per post type instead of site-wide, and how to clean up the revisions that have already piled up.

What Post Revisions Are actually For

Every time you click Update (or WordPress autosaves your draft, which happens automatically at a regular interval while you're editing), it stores a snapshot of that post's content as a separate row with post_type = 'revision'. This is what powers the Revisions screen you can reach from the post editor, letting you compare two versions side by side and restore an older one if you accidentally overwrite something you needed.

It's a genuinely useful safety net, especially for collaborative editing where more than one person touches the same post. The problem isn't the feature itself, it's the lack of any default limit, which means the value of keeping the 40th revision of a post is close to zero while still costing exactly as much storage as the first one.

Method 1: Limit the Number of Revisions Kept (Recommended)

Add this constant to wp-config.php, above the line that reads /* That's all, stop editing! */:

define( 'WP_POST_REVISIONS', 5 );

This caps every post and page at 5 stored revisions. Once a post's 6th revision is saved, WordPress automatically deletes its oldest stored revision to make room, so the count never exceeds 5, without you needing to do anything else. This is the setting worth using for the overwhelming majority of sites: it keeps a genuinely useful recent history while eliminating the unbounded growth.

Method 2: Disable Revisions Entirely

If you don't use the revision-comparison feature at all (common for sites where one person edits content and rarely reverts changes), you can turn revisions off completely:

define( 'WP_POST_REVISIONS', false );

Be aware this also disables autosave-to-revision entirely, not just manual revisions; WordPress still autosaves your current draft in progress (so you don't lose unsaved changes if your browser crashes), but it won't keep that autosave as a separate, restorable revision once you've published or updated the post.

Method 3: Limit Revisions Per Post Type With a Filter

WP_POST_REVISIONS in wp-config.php applies globally to every post type that supports revisions. If you want a different limit for, say, pages versus posts (pages tend to be edited less often and might warrant a smaller history), use the wp_revisions_to_keep filter in functions.php instead, which overrides the constant on a per-post-type basis:

add_filter( 'wp_revisions_to_keep', function ( $num, $post ) {
    if ( 'page' === $post->post_type ) {
        return 2;
    }

    if ( 'product' === $post->post_type ) {
        return 0; // No revisions for WooCommerce products.
    }

    return $num;
}, 10, 2 );

Returning 0 here disables revisions for that specific post type entirely, while everything else falls through to whatever $num already was (either your WP_POST_REVISIONS constant, or WordPress's default of unlimited if you haven't set one).

Adjusting the Autosave Interval

Related, but distinct: WordPress autosaves your current draft on a timer while you're actively editing, controlled by a separate constant, AUTOSAVE_INTERVAL, measured in seconds:

define( 'AUTOSAVE_INTERVAL', 120 ); // Autosave every 2 minutes instead of the 60-second default.

This doesn't directly control revision count the way WP_POST_REVISIONS does, but on a site where editors keep drafts open for a long time, a shorter interval means more frequent autosave writes to the database during that editing session, so lengthening it slightly can reduce database write load on very active editorial teams without meaningfully increasing the risk of lost work.

Cleaning Up Revisions That Already Exist

Setting WP_POST_REVISIONS only affects revisions created after you add the constant; it does nothing to the revisions already sitting in your database from before. Clean those up separately.

With WP-CLI:

wp post list --post_type=revision --format=ids | xargs -r wp post delete --force

With raw SQL, directly via phpMyAdmin or mysql:

DELETE FROM wp_posts WHERE post_type = 'revision';

Either command removes every existing revision immediately; going forward, your WP_POST_REVISIONS setting keeps the count capped automatically so you shouldn't need to repeat this regularly. This is one piece of a broader database cleanup and optimization pass worth running periodically, alongside clearing spam comments and expired transients.

Frequently Asked Questions (FAQ) About Limiting Post Revisions in WordPress

3 to 5 covers the vast majority of practical use cases, letting you step back through your last few edits without unbounded growth. Sites with heavy collaborative editing (multiple authors on the same post) might reasonably keep more, 10 or so, since there's more value in a longer history when several people are making changes.

No. WP_POST_REVISIONS only affects the revision history (past saved versions), never your post's current, live content. Setting it to false or a low number has zero effect on what's actually published and visible to visitors.

It affects whether that autosave gets kept as a restorable revision after you save. WordPress still autosaves your currently open draft to protect against a crashed browser tab regardless of this setting; WP_POST_REVISIONS controls whether that data persists as separate, comparable revision history afterward.

Yes, use the wp_revisions_to_keep filter shown above, checking $post->post_type inside the callback and returning a different number for each post type. The WP_POST_REVISIONS constant alone only supports one global number across every post type.

No, this is a single constant in wp-config.php, no plugin required. Some all-in-one performance plugins (like WP Rocket or WP-Optimize) offer a settings-page equivalent, which is convenient if you're already using one of them, but it isn't necessary just for this.

The constant only limits revisions created from that point forward; it doesn't retroactively delete existing ones. Run the WP-CLI or SQL cleanup command shown above once to clear out the backlog, after which the limit keeps the count in check going forward automatically.

On its own, the impact is usually modest, mostly reflected in a smaller database and slightly faster admin list screens and backups rather than a dramatic front-end speed change. It's still worth doing as one part of a broader database hygiene routine, alongside clearing spam comments and expired transients.

Conclusion

WP_POST_REVISIONS is one of the smallest changes in this entire performance and maintenance series, a single line in wp-config.php, and it closes off one of the most common, entirely avoidable sources of long-term database bloat. Setting it to a small number like 5 keeps the genuinely useful part of the revision feature (recent undo history) while eliminating the unbounded growth that comes from WordPress's uncapped default.

Pair it with a one-time cleanup of the revisions already sitting in your database, and a broader database optimization pass covering spam comments and expired transients too, and you've addressed one of the quieter, easy-to-overlook contributors to a slow, oversized WordPress database.

Here are a few additional resources if you want to go deeper:

Tags :
Share :

Related Posts

Effortlessly Crafting Compelling WordPress Pages

Effortlessly Crafting Compelling WordPress Pages

As a website owner or content creator, having the ability to seamlessly add new pages to your WordPress site is crucial. Whether you're introducing a

Continue Reading
High Traffic Tips for WordPress Mastery 🚥

High Traffic Tips for WordPress Mastery 🚥

In our digital age, where online visibility is paramount, ensuring your WordPress site can handle surging traffic is crucial. Just like a finely-tune

Continue Reading
How Do I Change the WordPress Login URL?

How Do I Change the WordPress Login URL?

By default, every WordPress site's login page lives at the same predictable address: yoursite.com/wp-login.php (which also happens to redirect from

Continue Reading