A quick one, but worth covering. If you’ve found this post, you probably already know why the WordPress Heartbeat matters; likely you’ve noticed excessive calls to wp-admin/admin-ajax.php, so I won’t patronise you or waste your time by explaining the basics. If, on the other hand, you don’t know what the WordPress Hearbeat API is, or why it matters, please read this, but don’t install the suggested plugin, at least not before reading and considering what’s below.

Hearbeat Control

Most posts out there (like the one linked to above) will tell you that, if you want to alter the frequency of the WordPress heartbeat, you should install the Heartbeat Control plugin. This is fine, if you’re a non-technical user. However, if you have some technical knowledge and are comfortable modifying the functions.php file, it makes little sense to add yet another plugin to the stack when you can achieve the desired result by adding 5 lines of code to your functions.php:

function limit_heartbeat($settings) {
    $settings['interval'] = 60; // Frequency of heartbeat in seconds (min: 15, max 120).
    return $settings;
}
add_filter('heartbeat_settings', 'limit_heartbeat');

Limit Heartbeat on specific pages

Altering the minimalInterval setting as above alters the frequency of autosave when creating and editing posts. If you’d like a different frequency in these instances, you know what to do (add a condition):

function limit_heartbeat($settings) {
    global $pagenow;

    // Check which page we're on, alter the interval if necessary.
    if (in_array($pagenow, array('new-post.php','edit.php')) {
        $settings['interval'] = 60; // Frequency of heartbeat in seconds (min: 15, max 120).
    }

    return $settings;
}
add_filter('heartbeat_settings', 'limit_heartbeat');

Completely disable the heartbeat

I wouldn’t recommend doing this, since it will affect WP’s handling of admin sessions, autosave and who knows what else. If you’re desperate to do so though, you just have to deregister the appropriate script:

function disable_heartbeat() {
    wp_deregister_script('heartbeat', 'remove_heartbeat', 1);
}
add_filter('init', 'disable_heartbeat');

Bonus: limit all WP AJAX requests

If you want to reduce the frequency of all WP AJAX requests, just substitute minimalInterval for interval:

function limit_heartbeat($settings) {
    $settings['minimalInterval'] = 60; // Frequency of heartbeat in seconds. (min: 1, max 60)
    return $settings;
}
add_filter('heartbeat_settings', 'limit_heartbeat');

The comments in the /wp-includes/js/heartbeat.js have this to say about the minimalInterval setting:

Used to limit the number of AJAX requests. Overrides all other intervals if they are shorter.

I’ve tested it and it does exactly what it says on the tin. If you find that interval doesn’t adequately reduce the calls to wp-admin/admin-ajax.php, try using minimalInterval instead. I recommended exploring the file for yourself if you’d like a deeper understanding of how exactly these settings are applied and used.

Why not just use the plugin?

When the change you need to make to your WordPress site is beyond your understanding, or the time and energy required to implement the change is beyond what you are willing to sacrifice, use a plugin. If none of the above is true, and the change you want to make is already provided by an existing plugin, but you don’t think you would create a significantly improved solution, use a plugin. Why reinvent the wheel, right?

However, if all that’s required to add a specific piece of functionality is essentially a copy and paste of a tiny sample of code into your functions.php (as is the case here), it seems like overkill to reach for a plugin. The WordPress Heartbeat frequency alteration is the type of thing you’ll probably set once and never need to touch again. Why bother with a plugin?

Each plugin you add to your WordPress site adds to the overhead. In some cases, that additional overhead is negligible, but often it’s not, and the cumulative effect can on occasion be crippling. Being selective — frugal, even — with the WordPress plugins you choose to use can save you a great deal of trouble further down the line.