For a few days ago I was experiencing a very slow WordPress loading speed even after using the high-power VPS, optimized images, compressed database, etc. In simple words, I was not doing anything wrong that could slow down WordPress but still, my WordPress was, again and again, giving server time-out errors and becoming slower along with time.
When I contacted my hosting support, they said “WordPress admin Ajax is using a lot of CPU. It’s caused due to WordPress Heartbeat API, and by limiting or disabling it, this problem can be fixed”. For more questions, they explained to me everything about this problem and how to fix it.
So, just as a blueprint from my hosting provider support and what else I experimented with while shorting out this problem, I’m via this article going to tell you what exactly the WordPress Heartbeat API is and how you can limit or disable it.
What is WordPress Heartbeat API?
You’ll be amazed to know that WordPress Heartbeat API is one of the great features of WordPress which provides a way for developers to trigger events.
Introduced in WordPress 3.6 the WordPress Heartbeat API allows WordPress to communicate between web-browser and the server. It’s essential for improved user session management, revision tracking, and auto-saving.
The WordPress Heartbeat API uses /wp-admin/admin-ajax.php to run AJAX calls from the web browser, which sounds awesome as WordPress can keep track of what’s going on in the dashboard but in some cases, it can increase your CPU usage and slow down your website due to excessive requests to admin-ajax.php.
So, if this great feature of WordPress is slowing down your website, without wasting a single minute you should limit or completely disable the Heartbeat API.
How to Limit or Disable WordPress Heartbeat API?
Disabling the WordPress Heartbeat API means you’re going to break out the connection between your web server and the web browser you’re working on, and in return going to miss the important features such as auto-saving, session management, revisions tracking, etc.
But, if you’re again and again seeing server connectivity errors on your site and very slow WordPress loading time, you should limit or disable the Heartbeat API for your WordPress website.
You can either limit or completely disable the WordPress Heartbeat API by using a WordPress plugin well-known as Heartbeat Control, which allows you to easily manage the frequency of WordPress Heartbeat API.
Installing & Activating the Plugin
First of all, login to your WordPress admin area and navigate to Plugins » Add New. On this page, enter Heartbeat Control into the search box At the top and press the Enter key on your keyboard to perform the search.
As you have searched for the exact name of the plugin, it should be the first result that appears. To install it, click on the Install Now button.
After completing the installation, don’t forget to click on Activate Now button to activate the plugin so that you can configure it according to you to limit or disable the Heartbeat API.
Limit or Disable Heartbeat using this Plugin
To limit or disable WordPress Heartbeat API, navigate to Settings » Heartbeat Control to configure the plugin.
From the ‘Control heartbeat locations’ option, you can select where you want to control heartbeat settings. You can disable it on the dashboard, allow it on post-edit pages, or completely disable it everywhere.
The next option allows you to control the frequency of the heartbeat. By default, heartbeat makes a post call every 15 seconds on post-edit pages, and every minute on the dashboard. You can choose a higher frequency.
Finally, after controlling the heartbeat location and setting up the frequency, just click the Save Changes button. That’s all, now you can easily limit the Heartbeat API or disable it completely by using this plugin. Isn’t it?
Disable WordPress Heartbeat API Without the Plugin
If you don’t want to limit the Heartbeat API instead willing to disable it completely, you can do it even without using any plugin.
All you need to copy and paste the following code snippet in your functions.php file, and the WordPress Heartbeat API will automatically be disabled completely.
add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}
That’s all friends! I hope this article will help understand what the Heartbeat API is and how it can be limited or disabled easily if something goes wrong.
Share this post if you liked it and leave your valuable thoughts on this tutorial. Also, let me know if you’ve any questions about WordPress Heartbeat API. I will be happy to help.
If every thing is going fine, will disabling this API will help in any further fast website loading? or in any other way…?
Doesn’t work for me unfortunately. I’m using Jupiter Theme and heartbeat control plugin is not working. Also added the code to function.php, but it doesn’t work. Kind of frustrating.
I was honestly confused a lot about the heartbeat API in WordPress. But, with the help of your post concept is very clear and now I can easily limit it. You’re really awesome man. Thanks.
I’m glad this tutorial could help you understand the concept of WordPress heartbeat API.
Very new thing for me. I’m a new blogger and didn’t know about it before. Thanks for this detailed info.
Great post sir. It’s very essential information not only for beginners but for everyone.
It’s my pleasure Ahmad. Thanks for your feedback.