The Heartbeat API sends periodic AJAX requests that can increase server load. Disabling it on the frontend can improve performance on busy sites.
Steps
- Open your WordPress theme
functions.phpfile. - Add the code below at the end of the file.
- Save the file.
- Clear any caches and test your website.
Done — the Heartbeat API will be disabled on the frontend while remaining available in the admin area.
Note: Some plugins rely on the Heartbeat API for frontend functionality. Test your site after enabling this snippet.
function disable_heartbeat_frontend() {
if (!is_admin()) {
wp_deregister_script('heartbeat');
}
}
add_action('init', 'disable_heartbeat_frontend', 1);
