← Back to All Snippets

Limit Maximum Post Revisions to 5 via Filter

⚡ Target: functions.php 🔒 Tested: WP 6.6+ / PHP 8.2+ 💻 Lang: PHP
PHP (functions.php)
add_filter( 'wp_revisions_to_keep', function( $num, $post ) {
    return 5; // Keep only the latest 5 revisions
}, 10, 2 );

Prevents database bloat in wp_posts by capping the maximum number of revisions stored per post to 5 without modifying wp-config.php.

← Back to All Snippets Explore Dev Tools →