Revision Limits per Post Type
Keeps a different number of revisions for each content type, for example many for posts and none for products.
Opens WPIDE on
Code
// Post type => revisions to keep (0 = none, -1 = unlimited). Other types keep the site default.
$wpide_revisions_by_type = array(
'post' => 10,
'page' => 5,
'product' => 0,
);
add_filter( 'wp_revisions_to_keep', function ( $num, $post ) use ( $wpide_revisions_by_type ) {
return isset( $wpide_revisions_by_type[ $post->post_type ] ) ? (int) $wpide_revisions_by_type[ $post->post_type ] : $num;
}, 10, 2 );
Notes
Older revisions beyond the limit are removed the next time the item is saved.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.