WordPress PHP Free

Limit WordPress Post Revisions and Slow Down Autosave

Stop WordPress filling your database with revisions: keep only 5 revisions per post and slow autosave to every 5 minutes.

10 lines · Updated Nov 26, 2026

Preview of Limit WordPress Post Revisions and Slow Down Autosave
limit-wordpress-post-revisions-and-autosave.php
<?php
// Keep at most 5 revisions per post.
add_filter( 'wp_revisions_to_keep', function ( $num, $post ) {
    return 5;
}, 10, 2 );

// Autosave every 5 minutes instead of every 60 seconds.
if ( ! defined( 'AUTOSAVE_INTERVAL' ) ) {
    define( 'AUTOSAVE_INTERVAL', 300 );
}

About this snippet

Every time you press Save or Update, WordPress stores a complete copy of the post as a revision — and it never deletes them on its own. On an active blog that quietly adds thousands of rows to the wp_posts table, which makes backups bigger, database queries slower and migrations more painful. This snippet caps how many revisions WordPress keeps and makes autosave run less often, so your database stays lean without losing the ability to undo recent changes.

How it works

  • A revision limit tells WordPress to keep only the most recent revisions for each post and discard older ones on the next save.
  • A longer autosave interval reduces how often the editor sends background saves while you write, which also reduces server requests on slow hosting.

How to use it

  1. Back up your site and database.
  2. Add the code where the install notes say — the constants must be defined before WordPress loads its settings, so placement matters.
  3. Edit and save any post twice, then open the Revisions panel to confirm the limit is applied.

Clean up revisions you already have

The limit only applies to future saves. To remove old revisions, use WP-CLI (wp post delete $(wp post list --post_type=revision --format=ids) --force) or a trusted database cleanup plugin — after taking a backup.

Common problems

  • Nothing changes: the constant was added after the line that loads WordPress settings, or a plugin overrides it.
  • Revisions disappear completely: a value of 0 or false disables revisions — use a small positive number instead.

FAQ

How many revisions should I keep? Three to ten is a sensible range for most blogs. Sites with many editors may want more.

Does this speed up my site? It mainly keeps the database smaller and backups faster. Front-end speed improvements are usually small but database-heavy admin pages benefit.

Related: 5 code snippets every developer needs · Disable comments on old posts

How to install

Add it to your child theme's functions.php, or — safer — paste it into the free Code Snippets plugin, where you can turn it on and off without touching any file. Never edit your parent theme's functions.php directly: one typo can lock you out of your site, and a theme update wipes your changes. After adding it, edit any post, save it a few times, and check that only 5 revisions are listed under the Revisions panel.

Share this snippet

See all
Chat with us