How to Stop WordPress Heartbeat Completely
Introduction to WordPress Heartbeat API
The WordPress Heartbeat allows your browser to communicate with the server when you're logged into the WordPress admin panel. This functionality allows WordPress to manage things like exhibiting other authors that a post is being edited by another user, plugins can use these script executions and show you notifications in real time, etc. Below is an example of Heartbeat in action while an author is trying edit a post currently managed by a second author.
Screenshot #1:
Screenshot #2:
Although it seems like a great functionality, the downside is that it may cause issues in certain cases. On different pages, Heartbeat makes checks on different period - on post edit, it makes it every 15 seconds, on your Dashboard - every minute, etc. Each "tick" generates a POST request which adds to the number of your executions and CPU time used.
This functionality uses the wp-admin/admin-ajax.php file to make AJAX calls. If you notice a significant amount of POST requests by that file, this means that you need to limit the work of Heartbeat or stop it completely.
Here's How You Can Stop WordPress Hearbeat
In most cases you can completely disable Heartbeat if you're the only person working at any given time in your site and you know that you don't have any important functionality that heavily relies on it to work properly.
To disable it, edit the functions.php file of your theme and paste these lines right after the opening <?php tag:
add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}
By applying the code above, Heartbeat functionality will be disabled and it will no longer add to the executions number and CPU time used in your account.
Implications of Stopping HeartBeat API:
Whether using plugin or modifying “functions.php” file, be aware of the following implications of completely stopping the heartbeat API.
Auto save and revisions will not work. This means you need to press the “Save Draft” button manually to save your content.
In case if the connectivity is lost and you unknowingly pressed “Publish / Update / Save Draft” button then the content you made online will be lost.
You may not be able to see real-time statistics and information if any of your installed plugin uses heartbeat API to update the content from server.
If any of the above point is a concern for you then instead of stopping the API look for upgrading server resources to handle high usage. Another solution is to limit the HeartBeat.
=> Click Here If You Just Want to Limit Heartbeat (Not Completely Disable)
Updated on: 03/01/2019
Thank you!