Skip to content

Instantly share code, notes, and snippets.

@skipshean
Last active March 12, 2022 07:01
Show Gist options
  • Save skipshean/94aaa50b3cc525fbcaba96b1699d11e5 to your computer and use it in GitHub Desktop.
Save skipshean/94aaa50b3cc525fbcaba96b1699d11e5 to your computer and use it in GitHub Desktop.
Limit or disable wordpress heartbeat to help speed up admin screens. Please in functions.php file.
// Limit or restrict WordPress heartbeat to speed up wp-admin when many browser tabs are open or traffic is high
// Taken from http://wordpress.stackexchange.com/questions/166727/how-can-i-speed-up-my-wp-admin-section
function optimize_heartbeat_settings( $settings ) {
$settings['autostart'] = false;
$settings['interval'] = 60;
return $settings;
}
add_filter( 'heartbeat_settings', 'optimize_heartbeat_settings' );
function disable_heartbeat_unless_post_edit_screen() {
global $pagenow;
if ( $pagenow != 'post.php' && $pagenow != 'post-new.php' )
wp_deregister_script('heartbeat');
}
add_action( 'init', 'disable_heartbeat_unless_post_edit_screen', 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment