Disabling or Limiting WordPress Post Revisions |
X

Congrats, You are Subscribed to Receive Updates.

Disabling or Limiting WordPress Post Revisions


Disabling or Limiting WordPress Post Revisions is one of a task to reduce consuming large database space. Also which helps to reduce your site load time.  Most of the articles helps to do the task. But all wants to edit the wp-config.php file to disable or limit the revisions. So here I am going to give you a easy function to reduce the risk and just do the functions from your admin panel.  the following function help you to limit the Revisions count.

add_filter( 'wp_revisions_to_keep', 'kv_set_revision_size', 10, 2 );

function kv_set_revision_size( $num, $post ) { 
    return 5;  //here allowed revisions are upto 5. 
}

If you are using more than one post type and need to limit independently, Use the following function to set each ones limit.

add_filter( 'wp_revisions_to_keep', 'kv_set_revision_size', 10, 2 );

function kv_set_revision_size( $num, $post ) { 
  
	if( 'kv_custom_post_type_name' == $post->post_type ) {
		$num = 3;
    } 
	if( 'kv_custom_post_type_name_next' == $post->post_type ) {
		$num = 6;
    } 
    return $num;
	
}

Add the above function to your theme “ functions.php” file or your plugins main file.  that’s it, it will take care of the post revisions based on the number count you specified in the functions.

disable-post-revisions

 

If you have any problem with using the code. Comment below.

 

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, PHP and Data Analyst. Database Management Advance Level

One comment

  1. commenter

    First tutorial which doesnt require editing wp-config.php. Kudos! This is indeed useful due to file permissions, also easily allows integrating this in theme or managing from WordPress admin panel

    thanks

Reply to Wordpress guy Cancel reply

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar