Change WordPress heartbeat rate to lower server load

WordPress heartbeat is made to save your articles automatically but it can slow down your server depending on your site size and all the plugins you got. If you’d like to stil use the feature but lower its saving rate, you can use the following code :

add_action( 'init', 'customize_heartbeat', 1 );

function customize_heartbeat() {

// Register the wordpress native script if necessary

if (!wp_script_is('heartbeat', 'registered')) {

wp_register_script('heartbeat', includes_url('js/heartbeat.min.js'), array('jquery'), null, true);

}

// Active with a custom interval

add_filter('heartbeat_settings', 'set_heartbeat_interval');

}

function set_heartbeat_interval($settings) {
 // Define interval in seconds
 $settings['interval'] = 120; // Example for 2 minutes (60x2)
 return $settings;
 }