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
// 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
- Install the snippet in Snipfire (it arrives switched off).
- Deactivate WP Revisions Control.
- Switch the snippet on. Snipfire checks the code and test-loads your site first.
- Check the page it affects, then delete the plugin.