# Disable the Heartbeat API Except in the Post Editor

> Keeps the Heartbeat API (autosave and post locking) in the editor but turns it off on every other admin and front-end page to save server requests.

- Type: PHP
- Runs: Run everywhere
- Category: [Performance](https://wpide.com/library/category/performance/)
- Tags: performance, heartbeat, admin-ajax
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/heartbeat-editor-only/

## Code

```php
add_action( 'admin_enqueue_scripts', function ( $hook ) {
    if ( ! in_array( $hook, array( 'post.php', 'post-new.php' ), true ) ) {
        wp_deregister_script( 'heartbeat' );
    }
}, 1 );

add_action( 'wp_enqueue_scripts', function () {
    wp_deregister_script( 'heartbeat' );
}, 1 );
```

## Notes

Some plugins rely on Heartbeat on their own screens; and the "session expired" login prompt only appears in the editor.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Disable the Heartbeat API Except in the Post Editor" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
