Control the WordPress Heartbeat API without a plugin
Slow the WordPress Heartbeat down to once a minute with a few lines of code. Heartbeat Control can also stop it or set rules per area; here is the difference.
What Heartbeat Control does
Heartbeat Control lets you slow down or stop the WordPress Heartbeat API, with separate rules for the dashboard, the post editor and the front end. The plugin on WordPress.org
What the snippet does the same
- Heartbeat checks with the server less often, which saves server work while the admin is open.
- Post locks and login checks keep working, because Heartbeat still runs once a minute.
What's different
- The snippet sets one interval, 60 seconds, wherever Heartbeat runs. The plugin can set different rules for the dashboard, the post editor and the front end.
- The plugin can stop Heartbeat completely. The snippet only slows it down.
- The plugin has a settings screen. With the snippet, you change the number of seconds in the code.
When to keep the plugin Keep the plugin if you want to stop Heartbeat entirely or set different rules for different parts of the site.
The snippet: Slow down the Heartbeat API
While the admin is open, WordPress checks in with the server every 15 to 60 seconds. Once a minute is enough for post locks and login checks, and saves server work.
<?php
add_filter(
'heartbeat_settings',
static function ( $settings ) {
$settings['interval'] = 60; // Seconds, between 15 and 120.
return $settings;
}
);
Notes, where it runs and what it was tested with
Switching from the plugin
- Install the snippet in Snipfire (it arrives switched off).
- Deactivate Heartbeat Control.
- Switch the snippet on. Snipfire checks the code and test-loads your site first.
- Check the page it affects, then delete the plugin.