WordPress Heartbeat API pings server every 15-60 seconds causing CPU spikes. Slow it down or disable.
Add to functions.php:
// Reduce heartbeat frequency
add_filter('heartbeat_settings', function($settings) {
$settings['interval'] = 60; // From 15-60 to 60 seconds
return $settings;
});
// Disable on frontend only (keep for editor autosave)
add_action('init', function() {
if (!is_admin()) {
wp_deregister_script('heartbeat');
}
});
// Disable completely except post editor
add_action('init', function() {
global $pagenow;
if ($pagenow !== 'post.php' && $pagenow !== 'post-new.php') {
wp_deregister_script('heartbeat');
}
});
Result:
Server requests: 4/min → 1/min
CPU usage: -80%
Hosting costs: Significantly lower on shared hosting
