How to Disable Autosave in WordPress (Block and Classic Editor)

Tested
What changed
Rewritten for current WordPress and tested on WordPress 7.1.
First written
2014
On this page: 7 sections

To disable autosave in today’s WordPress block editor, remove the autosave feature from your post types with a short snippet. If you only want fewer autosaves, set AUTOSAVE_INTERVAL in wp-config.php instead. The snippet most tutorials still give, wp_deregister_script( 'autosave' ), only affects the classic editor: in the block editor, autosave keeps running.

I tested every method below on WordPress 7.1 by editing posts in both editors and watching the autosave requests the browser sent.

What autosave does today

The block editor has two separate autosaves:

  • Server autosave. When you have unsaved changes, the editor sends them to WordPress every 60 seconds (the wp/v2/posts/<id>/autosaves REST endpoint). On a published post, WordPress stores them as a single autosave for each user and overwrites it every time. On your own draft, it updates the draft itself.
  • Browser backup. Every 15 seconds while you have unsaved changes, the editor also copies the title, content and excerpt into your browser’s session storage. Nothing is sent to the server, and the copy disappears when you close the tab. It is what you see when WordPress says “The backup of this post in your browser is different from the version below.”

The classic editor has the same pair, run by a different script (autosave.js, which sends its autosaves through the Heartbeat API).

Autosave is not the same as post revisions

If you want to turn off autosave because of database clutter, look at revisions instead. WordPress creates a new revision every time you click Save or Update. Autosave never adds more than one row per user per post, because each autosave overwrites the last one.

The two are controlled separately. In my test, define( 'WP_POST_REVISIONS', false ); stopped new revisions, but the editor kept autosaving every minute as before. If revisions are your problem, limit them with WP_POST_REVISIONS set to a number instead, and delete the old ones. Turning revisions off does not delete the revisions you already have.

Make autosave rare with AUTOSAVE_INTERVAL

This is the safest option: autosave still runs, just much less often. AUTOSAVE_INTERVAL is a constant, so it belongs in wp-config.php, not in a snippet. Open wp-config.php (in your host’s file manager or over FTP), make a backup copy, then add this line above /* That's all, stop editing! */:

define( 'AUTOSAVE_INTERVAL', 86400 );Code language: PHP (php)

The value is in seconds. The default is 60, and 86400 is one day. WordPress passes it to the block editor as the autosaveInterval setting and to the classic editor’s autosave.js, so it works in both. With it set, neither editor sent an autosave during my tests.

Two things still happen. The browser backup keeps running every 15 seconds, because this constant does not control it. And clicking Preview still saves your unsaved changes as an autosave so the preview can show them. That is usually what you want.

Do not use a bigger number. It is tempting to pick a huge value, but the block editor runs autosave on a browser timer that cannot count past about 24.8 days (2,147,483 seconds). In Chrome, when I set AUTOSAVE_INTERVAL to 2,147,484 or 3,000,000, the timer overflowed and the editor sent autosave requests several times a second instead of never. 86400 is long enough.

Turn autosave off completely

To stop autosave entirely, remove the autosave feature from your post types. In current WordPress, editor support includes autosave support unless you take it out. The block editor checks for the feature before every server autosave and every browser backup, and WordPress does not register the autosaves REST endpoint for post types without it.

// Block editor: turn off server autosave and the browser backup for posts and pages.
add_action( 'init', function () {
	foreach ( array( 'post', 'page' ) as $post_type ) {
		remove_post_type_support( $post_type, 'autosave' );
	}
}, 99 );

// Classic editor: it loads autosave.js regardless of post type support.
add_action( 'admin_init', function () {
	wp_deregister_script( 'autosave' );
} );Code language: PHP (php)

The first part covers the block editor. The second part is for sites that still use the classic editor (for example through the Classic Editor plugin). The classic editor loads autosave.js whether or not the post type supports autosave, so it has to be unregistered separately. If you only use the block editor, you can leave the second part out.

To include a custom post type, add its name to the array, for example array( 'post', 'page', 'product' ). The snippet runs late on init (priority 99), so post types that plugins register at the default priority already exist.

With this snippet active, the editor made no autosave requests and wrote no browser backup, in both editors. Normal saving and updating still worked. Know what you give up:

  • If the browser crashes or you lose your connection, everything since your last manual save is gone. There is no autosave or browser backup to restore.
  • Preview no longer includes unsaved changes. On a published post it shows the live version, on a draft the last saved draft. Save first, then preview.
  • An autosave saved before you added the snippet stays in the database, and the editor keeps offering it until you update the post. After that, WordPress deletes it the next time you open the editor.

Change the intervals with a snippet instead

If you cannot edit wp-config.php, or you want to change how often the browser backup runs, the block editor’s block_editor_settings_all filter can set both intervals. This only affects the block editor:

add_filter( 'block_editor_settings_all', function ( $settings ) {
	$settings['autosaveInterval']      = 600; // Server autosave: every 10 minutes.
	$settings['localAutosaveInterval'] = 60;  // Browser backup: every minute.
	return $settings;
} );Code language: PHP (php)

The values are in seconds. The same 24.8-day limit applies, so keep them well below 2,147,483.

Why the old snippet no longer works

Older tutorials, including the first version of this one, used this code:

add_action( 'admin_init', function () {
	wp_deregister_script( 'autosave' );
} );Code language: PHP (php)

It unregisters autosave.js, the classic editor’s autosave script, and in the classic editor it still works. But since WordPress 5.0, the default editor is the block editor, which never loads autosave.js. Its autosave is built into the editor itself and goes through the REST API. With only this snippet active, the block editor autosaved after a minute exactly as before, and the browser backup kept running. That is why the snippet above removes the autosave feature and keeps this code only for the classic editor.

The first version also said every autosave is stored as a new revision. It is not: there is one autosave per user per post, replaced each time.

Where to add this code

Add the snippet with a code snippets plugin instead of your theme’s functions.php, so it survives theme updates and you can switch it off without FTP. See how to add a code snippet safely, step by step with the free Code Snippets plugin. On my own sites I use WPCodeBox, which keeps snippets in a cloud library so the same snippet can go on several sites. Not sure which plugin to choose? I compared Code Snippets, WPCode and WPCodeBox by feeding each one broken snippets. (Marius)

Disclosure: the WPCodeBox link is an affiliate link. If you buy through it, I earn a commission at no extra cost to you.

More re-tested in WordPress

Leave a comment

Your email address won’t be published. Name, email and comment are required.