How To Modify or Disable WordPress Heartbeat API

WordPress Heartbeat API is introduced in version 3.6. Using this API, your browser can communicate with the server. On the page load, the heartbeat API sets up a code that runs every 15-60 seconds. When it runs, the heartbeat collects data to send via a jQuery event then sends this to the backend server and waits for a response.

Using Heartbeat, WordPress shows the authors a message like another user is editing the post. Plugins also use this API for script execution and to show a real-time notification to the users.

These are some of the cool features of Heartbeat API. However, it can also compromise your server performance. On each request, heartbeat sends an additional POST request to your server which adds an additional load on your server. To overcome such an issue, we can modify the heartbeat interval for sending requests or completely disable the Heartbeat API.

Modify or Disable Heartbeat API Using Plugin

The first thing you need to do is install and activate the Heartbeat Control plugin. Upon activation, you will find the settings under Settings->Heartbeat Control.

On this page, you will modify or disable the Heartbeat API.

The user can completely stop Heatbeat by selecting the Disable Heartbeat option.

Disable Heartbeat

In the same way, you can modify the heartbeat interval by selecting a Modify Heartbeat option and then setting a frequency.

Modify Heartbeat

Modify or Disable Heartbeat API Without Plugin

You can even control heartbeat API without using a plugin. In that case, you need to place a small piece of code in your active theme’s functions.php file.

The below code would completely disable the heartbeat API.

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

For modifying the heartbeat interval add the code as follows:

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' );

That’s it! You can choose either option of using a plugin or without a plugin to manage heartbeat API for better performance on your WordPress website.

We hope you understand how to modify or disable the WordPress heartbeat API. Please share your thoughts in the comments below.

Related Articles

If you liked this article, then please subscribe to our YouTube Channel for video tutorials.

1 thought on “How To Modify or Disable WordPress Heartbeat API

  1. Thanks. When adding the code to change the heartbeat frequency I get this error while trying to save the function file:
    Scrape nonce check failed. Please try again.

    Are you sure the code is correct? Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *