To deactivate Auto Save in all post, simply insert the following code into your ‘functions.php’ file in your theme directory or in your plugin file::
add_action( 'wp_print_scripts', 'disable_autosave' );
function disable_autosave() {
wp_deregister_script('autosave');
}
If you want to limit it to a custom post type:
add_action( 'wp_print_scripts', 'disable_autosave');
function disable_autosave() {
if ( ! function_exists( 'get_current_screen' ) )
require_once(ABSPATH . 'wp-admin/includes/screen.php');
$screen = get_current_screen();
if ( is_admin() && ($screen->id == 'post_type_name') ) {
wp_deregister_script('autosave');
}
}
Replace 'post_type_name' with your custom post type name.
In the previous code, we checked the current post type by using the function get_current_screen.
Note: we also checked if the function get_current_screen exists or not; otherwise you will have to require it once using:
require_once(ABSPATH . 'wp-admin/includes/screen.php');
No comments:
Post a Comment