Reduces database bloat by setting different revision limits based on post type instead of applying a static global limit in wp-config.php.
add_filter( 'wp_revisions_to_keep', 'set_custom_revision_limits', 10, 2 );
function set_custom_revision_limits( $num, $post ) {
switch ( $post->post_type ) {
case 'post':
return 5; // Keep up to 5 revisions for blog posts
case 'page':
return 10; // Keep up to 10 revisions for critical pages
case 'product':
return 2; // Keep only 2 revisions for WooCommerce products
default:
return 0; // Disable revisions for custom post types
}
}
Tested on
WordPress 7.1
Reported by the author on October 27, 2026. WPFolks has not verified this.
