WordPress Heartbeat API (A great tool for plugin developers to do some amazing tasks), introduced in WordPress 3.6. Most of the plugin developers use this Heartbeat API to show you notifications in real time, etc.
This heartbeat API is good for plugin developers but it can kill your WordPress site by increasing web hosting resource usage. If you are using shared hosting for your WordPress site, it can create a big problem for you.
If your web hosting provider has strict limits on the number of processes or resources, you could go over the limit and your hosting account may suspend by your hosting provider.
In this tutorial, I will show you how to limit or disable WordPress heartbeat API. Below is the complete tutorial on WordPress Heartbeat API.
How WordPress Heartbeat API Works
This heartbeat API uses /wp-admin/admin-ajax.php to run AJAX calls from the web browser. WordPress can keep track of your site dashboard with the help of this API.
Let me show you a better example. Suppose if all you did was login to your WordPress admin panel and then minimized that window for some time, you’d see requests for admin-ajax.php in your site’s access logs. This is the pulse generated by WordPress Heartbeat.
However, even though this is great functionality by WordPress but it may cause issues in certain cases. When you edit your post or page, it will generate the pulse in every 15 seconds.
If you have too many requests, then your server will slow down. That’s the main problem with this great API.
How to Limit WordPress Heartbeat API
If you want to control or limit your WordPress heartbeat, you can use Heartbeat Control plugin. It allows you to control the interval of pulses. Upon activation, go to Settings » Heartbeat Control Settings to configure the plugin.
On Heartbeat Control Settings page, you need to add a new rule to control the heartbeat. Don’t worry, I will show you how to do that.
From the Heartbeat Behavior option, you can allow, disable, or modify WordPress Heartbeat. To change the frequency of Heartbeat API, you need to select Modify Heartbeat from Heartbeat Behavior option.
Now it will show a new option (Frequency) after selecting Modify Heartbeat. Here you can change the frequency of heartbeat API. By default, Heartbeat API makes a post call every 15 seconds on post edit pages and every minute on the WordPress admin dashboard.
I would recommend that you choose 60 seconds frequency time for Heartbeat API.
With this plugin, you can also select where you want to control heartbeat settings. You just need to tick the checkboxes to select the locations.
When you are done, click on Save Changes button to apply your settings. That’s it. Now plugin will take care of your heartbeat API. With this method, you can easily limit the heartbeat API of your WordPress site.
How to Disable WordPress Heartbeat API without Plugin
Most of the WordPress users don’t like to use too many plugins on their site because it can lead to high CPU usage. Now I will show you to how to disable heartbeat API without using any plugin.
With this method, you can disable API entirely on your WordPress site. You can’t use this amazing functionality after disabling it.
Make sure you are a single user on your site and you don’t need any features made possible by the API, then you can disable it.
Below is the code to disable heartbeat API on entire site. You need to copy and paste this code into your theme functions.php file. Make sure you are using child theme, otherwise the changes will be lost with the next theme update.
Note: Backup the functions.php file before editing.
add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}
Now you are done. You have successfully disabled the WordPress heartbeat API on your entire site.
If you control the heartbeat API, pulses are less likely to impact on server performance. Several users who use this method to control API report they no longer experience suspensions for using too many resources.
I hope you like this tutorial, you can support us by sharing this post on Instagram, Twitter and or subscribe to our newsletter for more useful tutorials.
Leave a Reply