← Back to All Snippets

Disable WordPress Heartbeat API Except on Post Edit Screen

⚡ Target: functions.php 🔒 Tested: WP 6.6+ / PHP 8.2+ 💻 Lang: PHP
PHP (functions.php)
add_action( 'init', function() {
    global $pagenow;
    if ( 'post.php' !== $pagenow && 'post-new.php' !== $pagenow ) {
        wp_deregister_script( 'heartbeat' );
    }
}, 1 );

The WordPress Heartbeat API sends frequent AJAX requests (/wp-admin/admin-ajax.php) every 15-60 seconds, which can overload CPU on shared and VPS hosting. This snippet disables heartbeat globally except while drafting posts.

← Back to All Snippets Explore Dev Tools →