WordPress

WordPress How To Optimize Heartbeat Without A Plugin

WordPress is the most popular CMS in the world and a common mantra that you see in the developer community is to optimize the performance by reducing the number of plugins. While there is some truth to this mantra its largely over stressed and causes users to create kitchen sink plugins or put too much stuff within their functions.php files.

That being said there is no reason to add heart beat control which will simply clutter your admin panel when you can simply add the code to limit the heart beat “beats”. To do this you may add this code to your own Site Specific plugin or child theme functions.php file.

I recommend using it in your own specific site plugin in order to keep these settings cross themes. This will not add any branding, admin menu, anything to the front or back end to the site all it does is change the interval of which the heartbeat api beats on the site. The code is actually quite simple and can be easily changed. You can increase or decrease the interval, add it to your own plugin, or simply just paste it into your blog and reduce your server load.

$heartbeat_location = get_option(‘heartbeat_location’);
$heartbeat_frequency = get_option(‘heartbeat_frequency’);

if ( is_numeric( $heartbeat_frequency ) ) {
function heartbeat_frequency( $settings ) {
global $heartbeat_frequency;
$settings[’60’] = $heartbeat_frequency;
return $settings;
}

add_filter( ‘heartbeat_settings’, ‘heartbeat_frequency’ );
}

By adding this code you will increase the interval of beats to 60 and to change the interval to an even higher number or a lower number you could simply edit the ’60’ to a number in seconds you would like it to beat.

The reason we did not simply remove the heart beat api was to make sure your site still functions correctly, while this can be done the heart beat api does serve an important purpose in many plugins and it is used even by WordPress Core in many areas. By increasing the interval though, you can reduce the load on your server and improve server response time for users who may or may not be sticking around on your site.

Tags
Show More

Scott Hartley

Scott Hartley is the developer and owner of The Daily Exposition who is also a tech enthusiast and writes the majority of content found on the website. When he isn’t keeping up to date with the latest and breaking technology news, he is working on his own WordPress plugins, themes, or out exploring the world.

Leave a Reply

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

Close