Modify or Disable Heartbeat API Without Plugin

Marko Krstić
21 Apr 2021

In 2013 WordPress introduces Heartbeat API – a feature that allows your browser to automatically communicate with the server. However, there are a couple of drawbacks to this feature.

If you use a shared hosting plan, you need to take a closer look at the CPU usage of your server. That’s because some hosting companies might suspend your account when you go over the limit.

Here, we’ll talk why WordPress Heartbeat API is it the usual suspect that causes the issue.

Stop Heartbeat Code

<?php

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

?>

Modify Heartbeat Code

Replace 100 (seconds ) if you need.

<?php

function change_frequency_of_heartbeat_settings( $settings ) {
    $settings['interval'] = 100; //Anything between 15-120
    return $settings;
}
add_filter( 'heartbeat_settings', 'change_frequency_of_heartbeat_settings' );

?>

Add Code Snippet

Open Scripts Organizer

Hit Add new.

screenshot 2021 04 15 at 21.25.39

Scripts Organizer Settings

Trigger Location: Everywhere
Script Location: PHP

screenshot 2021 04 15 at 21.29.12 1

Was this article helpful?

Tags

Categories

Never miss new post again

Subscribe and get list of new posts in your inbox

Click to Copy