Limit Heartbeat Without a Plugin

Would you like to limit the number of wordpress heartbeat ticks without a plugin?

Put this snippet in your functions.php file (or create a simple plugin).

function az_wp_heartbeat_settings( $settings ) {
    // Anything between 15-120 
    // The javascript code maxes out at 120 seconds as the upper limit presumably to manage tasks like post edit locks
    $settings['interval'] = 120; 
    return $settings;
}
add_filter( 'heartbeat_settings', 'az_wp_heartbeat_settings' );

You can set the minimum interval instead up to 600 which would override the ‘interval’ element so you don’t need to include it. This documentation block explains setting $settings[‘minimalInterval’]:

/*
* Used to limit the number of AJAX requests. Overrides all other intervals if
* they are shorter. Needed for some hosts that cannot handle frequent requests
* and the user may exceed the allocated server CPU time, etc. The minimal
* interval can be up to 600 sec. however setting it to longer than 120 sec.
* will limit or disable some of the functionality (like post locks). Once set
* at initialization, minimalInterval cannot be changed/overridden.
*/
function az_wp_heartbeat_settings_min( $settings ) {
    $settings['minimalInterval'] = 600;
    return $settings;
}
add_filter( 'heartbeat_settings', 'az_wp_heartbeat_settings_min' );

This filter is in the file wp-includes/js/heartbeat.js