What is the WordPress Heartbeat API?

WordPress Heartbeat API

First appearing in WordPress 3.6, the WordPress Heartbeat API allows your web browser to communicate with the actual web server. This "heartbeat" is sent over intervals continuously. While this allows functionality such as plugins being able display real-time updates as well other many other functions, it can cause extensive resource usage.


How Do I Know If This is Causing Performance Issues For My Site?

The WordPress Heartbeat uses the file wp-admin/admin-ajax.php to make AJAX calls. You can use a command such as Top from your cPanel's Terminal (or via SSH) to see if you notice a large amount of the admin-ajax.php file being ran by your site.


How Can I Disable This or Change How Often This Heartbeat Occurs?

If there are not multiple authors for your site (the heartbeat allows you to see if someone else is editing the same post), you may wish to simply disable this functionality completely. The WordPress Heartbeat can be disabled via many different methods:

Completely Disable WordPress Heartbeat (Will Be Disabled on any Theme):

This method would be the recommended method to utilize as unlike with editing your functions.php file, the heartbeat will remain disabled even when changing to a different theme.


Once you have opened the plugins.php file, you may add the following code to the top of the file, and save:

add_action( 'init', 'kill_heartbeat', 1 ); function kill_heartbeat() { global $pagenow; wp_deregister_script('heartbeat'); } 

Completely Disable WordPress Heartbeat (Theme Specific):

You can edit your theme's function.php file to completely disable the WordPress Heartbeat only when using a specific theme.


Once you have opened the functions.php file, you may add the following code to the top of the file, and save:

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

Change The Interval In Which The Heartbeat Occurs:

If you would like to change how often the Heartbeat Occurs, rather than disable it you can use also use your functions.php file as mentioned above, and add the following code:

add_filter( 'heartbeat_send', 'my_heartbeat_settings' ); function my_heartbeat_settings( $response ) { if ( $_POST['interval'] != 60 ) { $response['heartbeat_interval'] = 60; } return $response; } 

*Please note that the above code sets the interval to 60 seconds (the default interval is 15 seconds). This may be adjusted accordingly.


Alternatively, there is the third party plugin HeartBeat Control which allows you to due this through a simple plugin interface. The following third party Youtube Link will provide details regarding the many features available from the plugin: https://www.youtube.com/watch?v=of0GCD_mlMs 

Was this article helpful?
0 out of 0 found this helpful