The WordPress Heartbeat API is a polling mechanism that fires recurring AJAX requests to /wp-admin/admin-ajax.php at regular intervals. It was introduced to power autosave, post locking (the “someone else is editing this” notice), and user session management. On the surface this sounds essential, but in practice Heartbeat runs far more broadly than its features require, firing on every front-end page view for logged-in users, on every admin page, and by default at an interval of 15 seconds. This snippet gives you a complete control panel with five independent configuration options.
How to Use This Snippet
The code is structured as five independent, commented sections. Read each section’s description and uncomment the ones that match your needs. Options 1 and 2 are the recommended baseline for virtually every site. Options 3, 4, and 5 are for more specific requirements. You can combine options freely, for example, running option 1 (disable on frontend) and option 3 (admin except post editor) together gives you the most efficient configuration while preserving autosave.
Option 1: Disable on the Frontend
This is the most impactful single change and is safe for all sites. No front-end feature requires Heartbeat. The only reason it runs on the frontend by default is to keep the user session alive for logged-in users. Session management can be handled by other means, and for sites where session persistence on the frontend matters, the cost of Heartbeat is typically not worth it. Disabling it eliminates all front-end AJAX polling entirely.
Option 2: Throttle in the Admin
Setting the interval to 60 seconds, the maximum WordPress allows, reduces polling frequency by 75% compared to the default 15-second interval. This alone significantly reduces the server load Heartbeat generates on busy admin sessions, particularly on sites with multiple editors working simultaneously. Autosave and post locking continue to work; they just check in less frequently.
Option 3: Admin Except Post Editor
This is the most surgical option for the admin. The post editor (post.php and post-new.php) is where Heartbeat’s features, autosave and post locking, are genuinely used. Every other admin page gets Heartbeat removed entirely. This is stricter than option 2 but preserves the features that matter.
Option 4: Disable Everywhere
Complete removal. Autosave stops working and post locking is disabled. Appropriate for sites managed by a single administrator who uses manual saves, or for sites where the performance overhead of any polling is unacceptable. Not recommended for multi-author sites.
Option 5: Per-Page Control
For fine-grained control, you can target specific admin pages by their hook name. The hook name is the string passed to admin_enqueue_scripts and corresponds to the admin page being loaded. Common values include dashboard, plugins, upload (Media Library), and options-general (General Settings). To find the hook name for any admin page, temporarily add add_action('admin_enqueue_scripts', function($hook){ error_log($hook); }); and check your error log while visiting that page.
/**
* WordPress Heartbeat API Control Panel
*
* HOW TO USE:
* Uncomment the sections you want to apply.
* Each section is independent, mix and match to suit your site.
*
* WHAT IS HEARTBEAT?
* The Heartbeat API fires recurring AJAX requests to /wp-admin/admin-ajax.php
* to power autosave, post locking, and logged-in session management.
* Default interval: 15–60 seconds depending on context.
*/
/* ── 1. DISABLE ON THE FRONTEND (recommended for all sites) ──────────────── */
// Removes Heartbeat entirely for all front-end page views.
// Safe: no front-end feature requires Heartbeat.
add_action( 'init', function() {
if ( ! is_admin() ) {
wp_deregister_script( 'heartbeat' );
}
}, 1 );
/* ── 2. THROTTLE IN THE ADMIN (recommended for all sites) ───────────────── */
// Slows Heartbeat from 15s to 60s (the maximum) in the admin.
// Cuts polling by 75% without disabling any feature.
add_filter( 'heartbeat_settings', function( $settings ) {
$settings['interval'] = 60; // seconds, valid range: 15–60
return $settings;
} );
/* ── 3. DISABLE IN ADMIN EXCEPT ON POST EDITOR ──────────────────────────── */
// Keeps Heartbeat active on post.php and post-new.php (autosave + post lock)
// but removes it from all other admin pages (dashboard, settings, etc.).
// Uncomment to use instead of option 2 above.
// add_action( 'admin_enqueue_scripts', function( $hook ) {
// if ( $hook !== 'post.php' && $hook !== 'post-new.php' ) {
// wp_deregister_script( 'heartbeat' );
// }
// }, 1 );
/* ── 4. DISABLE EVERYWHERE (aggressive, may affect autosave) ───────────── */
// Removes Heartbeat from both frontend and admin.
// Autosave and post locking will stop working.
// Only use on sites where these features are not needed.
// add_action( 'init', function() {
// wp_deregister_script( 'heartbeat' );
// }, 1 );
/* ── 5. PER-PAGE CONTROL (advanced) ─────────────────────────────────────── */
// Disable Heartbeat on specific admin pages by hook name.
// Run get_current_screen()->id in a template to find a page's hook name.
// add_action( 'admin_enqueue_scripts', function( $hook ) {
// $disable_on = [ 'dashboard', 'plugins', 'upload', 'options-general' ];
// if ( in_array( $hook, $disable_on, true ) ) {
// wp_deregister_script( 'heartbeat' );
// }
// }, 1 );
