The WordPress Heartbeat API is a built-in AJAX polling mechanism introduced in WordPress 3.6 that sends a POST request to wp-admin/admin-ajax.php every 15–60 seconds while a user has an admin page or post editor open. Its primary purposes are autosaving post content, maintaining the user session to prevent logged-out timeouts, and enabling the post-locking system that prevents two editors from editing the same post simultaneously. The problem is that on shared hosting or sites with many simultaneous logged-in admins, these constant AJAX requests can cause noticeable server load spikes. Each heartbeat request goes through the full WordPress bootstrap, runs database queries, and returns a JSON response — the same overhead as any other WordPress page request. The fix is not to disable the Heartbeat API entirely (you’ll lose autosave and session maintenance), but to slow it down in contexts where it fires too frequently, or stop it on the front end where it should never run. The heartbeat_settings filter lets you control the interval (in seconds) per admin screen. The wp_enqueue_scripts and admin_enqueue_scripts hooks let you dequeue the Heartbeat script entirely on specific pages. This is one of several admin performance tweaks worth combining with query string removal and the Transients API for caching.
Problem: The WordPress Heartbeat API is generating constant AJAX requests that spike server CPU on shared hosting, especially with multiple editors open simultaneously.
Solution: Add the following code to your functions.php file:
add_filter( 'heartbeat_settings', 'helloadmin_heartbeat_settings', 10, 2 );
function helloadmin_heartbeat_settings( array $settings, string $page ): array {
// Slow down heartbeat to 60 seconds on all admin pages
$settings['interval'] = 60;
// On the post editor, keep it at 30 seconds (for autosave to work reasonably)
if ( 'post.php' === $page || 'post-new.php' === $page ) {
$settings['interval'] = 30;
}
return $settings;
}
// Disable heartbeat completely on the front end and dashboard (not the editor)
add_action( 'init', 'helloadmin_disable_heartbeat', 1 );
function helloadmin_disable_heartbeat() {
global $pagenow;
// Allow heartbeat on post editor and profile pages only
$allowed_pages = [ 'post.php', 'post-new.php', 'profile.php' ];
if ( is_admin() && ! in_array( $pagenow, $allowed_pages, true ) ) {
wp_deregister_script( 'heartbeat' );
}
// Always disable on the front end
if ( ! is_admin() ) {
wp_deregister_script( 'heartbeat' );
}
}
// Limit autosave interval to 120 seconds (default is 60 seconds)
add_filter( 'autosave_interval', fn() => 120 );
NOTE: Never disable the Heartbeat API on the post editor screen if you use post locking or rely on autosave — these features depend on it. Disabling heartbeat on the Dashboard and other non-editor admin pages is perfectly safe and reduces unnecessary load. On WooCommerce sites, WooCommerce itself uses the Heartbeat API for the “new order” notifications in the admin bar — if you disable heartbeat on the Dashboard, those real-time notifications will stop. Use wp_dequeue_script instead of wp_deregister_script if other plugins have already enqueued it.