Control the Heartbeat API
Stops Heartbeat on the front end and slows it down in wp-admin. The post editor keeps it, so autosave and post locking still work.
add_action( 'init', function() {
if ( ! is_admin() ) {
wp_deregister_script( 'heartbeat' ); // Not needed on the front end.
}
}, 1 );
add_filter( 'heartbeat_settings', function( $settings ) {
global $pagenow;
if ( ! in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) {
$settings['interval'] = 60; // The editor keeps its own pace.
}
return $settings;
} );
These are the default values. Change them in the builder before you copy. Licensed under GPL-2.0-or-later, provided as is. Review and test it before using it on a live site.
How it works
Heartbeat is a script that calls admin-ajax.php every 15 to 60 seconds while WordPress is open in a browser. Each call is a full PHP request, so a few open wp-admin tabs keep the server busy, which shows on shared hosting. The snippet removes the script on the front end and uses the heartbeat_settings filter to set a slower interval in wp-admin.
Why not turn it off completely
Autosave, post locking (the “someone else is editing” notice), the login expired popup and nonce refresh all run on Heartbeat. That’s why the post editor is left as it is. Everywhere else, only the pace changes.
Before you use it
- Set the interval in the builder, under Interval in wp-admin (seconds). 60 is a good balance.
- If a plugin shows live data on the front end, for example a chat or a live stock counter, check it still updates.
How to check it works
Open the dashboard with your browser’s Network tab filtered by admin-ajax. Requests should arrive at your interval. On the front end, heartbeat.min.js should no longer load.
How to undo it
Remove the code.
How to add this snippet
- Copy the code above.
- Paste it at the end of your child theme’s
functions.php, in Appearance → Theme File Editor or over FTP. - Save, then open the site and check that everything works. If something breaks, remove the code.
Need more than one? Open this snippet in the builder, turn on the others you want and copy them as one functions.php, or download them as a small plugin.
More in Performance
- Disable the emoji scriptsOne less script on every page. Browsers render emoji natively anyway.
init - Remove Gutenberg CSS on the front endFor sites built with Elementor or the classic editor.
wp_enqueue_scripts - Limit post revisionsKeeps the database from filling up with hundreds of old revisions.
wp_revisions_to_keep