How to Control the WordPress Heartbeat API

The WordPress Heartbeat API sends periodic AJAX requests from the browser to the server to power features like post locking, autosave, and session keep-alive. On shared hosting or high-traffic sites, these requests can pile up and cause noticeable server load. Fortunately, the API is easy to throttle or disable selectively.

Problem: The WordPress Heartbeat API sends AJAX requests to the server every 15–60 seconds, causing CPU spikes on shared hosting — especially on sites with many concurrent logged-in users or on dashboard-heavy admin pages.

Solution: Use the heartbeat_settings filter to increase the interval, or wp_deregister_script('heartbeat') inside a conditional to disable it selectively on the front end — keep it active in the post editor where autosave and post-lock depend on it.

Reduce the heartbeat interval on the post editor and disable it everywhere else:

add_filter( 'heartbeat_settings', 'optimise_heartbeat_settings' );

function optimise_heartbeat_settings( $settings ) {
    // Slow down the interval from 15s (default) to 60s
    $settings['interval'] = 60;
    return $settings;
}

// Disable Heartbeat completely on the front end and in the dashboard
// but keep it on the post editor (autosave / post lock)
add_action( 'init', 'control_heartbeat_locations', 1 );

function control_heartbeat_locations() {
    global $pagenow;

    // Allow heartbeat only on post.php and post-new.php
    if ( $pagenow !== 'post.php' && $pagenow !== 'post-new.php' ) {
        wp_deregister_script( 'heartbeat' );
    }
}

If you need to disable the Heartbeat API entirely (for example on a static marketing site where no one logs in to edit posts):

add_action( 'init', function() {
    wp_deregister_script( 'heartbeat' );
}, 1 );

Verify the result — open the browser Network tab on the admin dashboard and confirm that admin-ajax.php requests no longer fire every 15 seconds.

NOTE: Disabling the Heartbeat API on the post editor also disables post locking — two editors can open the same post without being warned that someone else is working on it. Only disable it on the editor if you are the sole content author, or if post locking is handled by a different mechanism.