Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Limit post revisions in WordPress without a plugin

Keep only the last 10 revisions of each post with one line of code. WP Revisions Control lets you set limits per post type and purge old ones; here is the comparison.

What WP Revisions Control does

WP Revisions Control lets you set how many revisions WordPress keeps for each post type, from Settings > Writing. The plugin on WordPress.org

What the snippet does the same

  • WordPress keeps a set number of revisions instead of every one, so the database doesn't fill up with old versions.
  • Both use the same WordPress filter. Older revisions beyond the limit are removed the next time a post is saved.

What's different

  • The snippet keeps 10 revisions for every post type. You change the number in the code, and 0 turns revisions off. The plugin lets you set a different number for each post type.
  • The plugin can also set a limit for a single post, and purge revisions from the edit screen or with bulk actions. The snippet has no purge button.

When to keep the plugin Keep the plugin if you want different limits for different post types or need to purge old revisions now.

The snippet: Keep 10 revisions per post

Keeps the last 10 revisions of each post and page instead of every one, so the database doesn’t fill up with old versions.

PHP
<?php

// Change 10 to the number you want to keep (0 turns revisions off).
add_filter( 'wp_revisions_to_keep', static fn() => 10 );

Notes, where it runs and what it was tested with

Switching from the plugin

  1. Install the snippet in Snipfire (it arrives switched off).
  2. Deactivate WP Revisions Control.
  3. Switch the snippet on. Snipfire checks the code and test-loads your site first.
  4. Check the page it affects, then delete the plugin.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.