The WordPress Heartbeat API sends periodic AJAX requests from the browser to the server while a user is logged into the admin. It powers autosave, post locking (“someone else is editing this post”), and session extension. The downside: on shared hosting it can generate dozens of extra server requests per minute per logged-in user.
Problem: The WordPress Heartbeat API sends frequent AJAX requests to the server that can spike CPU usage on shared hosting — how do you control or disable it?
Solution: Use the heartbeat_settings filter to increase the interval or disable Heartbeat completely on the front end, and the heartbeat_send filter to limit data sent. Keep it active in the post editor where autosave depends on it.
Reduce or disable the Heartbeat frequency in functions.php:
add_filter( 'heartbeat_settings', 'adjust_heartbeat_settings' );
function adjust_heartbeat_settings( $settings ) {
// Default interval is 15 seconds; increase to 60 to reduce server load
$settings['interval'] = 60;
return $settings;
}
// Disable Heartbeat on the front end and dashboard (keep only on post edit screen)
add_action( 'init', 'control_heartbeat_load' );
function control_heartbeat_load() {
global $pagenow;
if ( is_admin() && 'post.php' === $pagenow ) {
return; // keep Heartbeat active for post editing (autosave / post lock)
}
wp_deregister_script( 'heartbeat' );
}
Sending and receiving custom data through Heartbeat — for example, a live notification count:
// In your admin JavaScript file
jQuery( document ).on( 'heartbeat-send', function( e, data ) {
data.myPlugin = { checkNotifications: true };
} );
jQuery( document ).on( 'heartbeat-tick', function( e, data ) {
if ( data.myPlugin && data.myPlugin.count ) {
jQuery( '#notification-badge' ).text( data.myPlugin.count );
}
} );
// In PHP — respond to the Heartbeat request
add_filter( 'heartbeat_received', 'my_heartbeat_response', 10, 2 );
function my_heartbeat_response( $response, $data ) {
if ( ! empty( $data['myPlugin']['checkNotifications'] ) ) {
$response['myPlugin'] = [
'count' => get_user_meta( get_current_user_id(), '_unread_notifications', true ) ?: 0,
];
}
return $response;
}
NOTE: Completely disabling the Heartbeat on post edit screens will also disable autosave and post locking — a trade-off that may not be worth it on multi-author sites. If server load is the concern, increasing the interval to 60 seconds is a safer compromise.