Hook Name: wp_revisions_to_keep
Explanation: The wp_revisions_to_keep hook is a WordPress filter that allows developers to modify the number of revisions to keep for each post or page. By default, WordPress stores a revision for every save made to a post or page, which can cause an inflated database size over time. This hook provides a way to control the maximum number of revisions to keep for each post type.
Usage: To change the default number of revisions to keep, you can use the wp_revisions_to_keep filter in your theme’s functions.php file or in a custom plugin. Here’s an example code snippet:
function custom_revisions_to_keep( $num, $post ) {
// Set the desired number of revisions to keep
$num = 5; // Change this to the desired number
return $num;
}
add_filter( 'wp_revisions_to_keep', 'custom_revisions_to_keep', 10, 2 );
In this example, we define a custom_revisions_to_keep function that takes two parameters: $num (the default number of revisions) and $post (the post object). Within the function, we set the $num variable to the desired number of revisions to keep (in this case, 5). Finally, we use the add_filter function to attach our custom_revisions_to_keep function to the wp_revisions_to_keep hook.
By using this filter, you can easily limit the number of revisions stored for each post or page, helping to optimize your WordPress database and improve overall performance.