The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Per-Post-Type Revision Limits

Shared by Jainil Nagar · October 27, 2026 · @wp_revisions_to_keep

4 views
Back to Snippets

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.

Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments

Proudly supported by