All posts

Blog

WordPress Revisions and Autosave: How to Restore, Limit and Clean Up Revisions

Illustrated cover for the WordPress guide "WordPress Revisions and Autosave: How to Restore, Limit and Clean Up Revisions"

You spent an hour rewriting a post, then realized the original intro was better. Or a colleague overwrote your changes. Or your browser crashed mid-sentence. In each case, WordPress has probably saved you already. Its revisions and autosave features keep earlier versions of your content so you can roll back.

This guide explains how WordPress revisions and autosave work, how to restore an older version, and how to keep revisions under control so they do not bloat your database.

What are WordPress revisions?

A revision is a saved copy of a post or page at a point in time. Each time you click Save draft, Update or Publish, WordPress stores the previous version as a revision before saving the new one.

Revisions are stored in the database, in the same wp_posts table as your content, with a post type of revision. They record the title, content and excerpt. They do not record everything, though: changes to featured images, categories, tags and most custom fields are not kept in revisions by default.

Revisions work for posts and pages out of the box, and for custom post types that enable them. Block themes also keep revisions of global styles and templates edited in the Site Editor.

What is autosave?

Autosave is separate from regular revisions. While you are editing, WordPress automatically saves your work in the background, by default every 60 seconds.

A few things to know about autosave:

  • WordPress keeps one autosave per user per post. Each new autosave replaces the previous one, so autosaves do not pile up.
  • For drafts, autosave updates the draft itself.
  • For published posts, autosave stores your unsaved changes separately, so visitors do not see half-finished edits.
  • If you leave the editor without saving and come back, WordPress shows a notice: "There is an autosave of this post that is more recent than the version below." You can then restore it.

The block editor also keeps a local backup in your browser. If your connection drops or the browser crashes, you may see a prompt to restore the backup of the post when you return.

How to restore a previous revision

  1. Open the post or page in the editor.
  2. In the settings sidebar, under the Post (or Page) tab, look for Revisions along with the number saved. Click it.
  3. The revisions screen shows a slider across the top. Drag it, or use the Previous and Next buttons, to move between versions.
  4. Each view compares two versions side by side, with removed text highlighted in red and added text in green.
  5. To compare any two versions instead of neighboring ones, tick Compare any two revisions and drag both handles.
  6. When you find the version you want, click Restore This Revision.

Restoring does not delete anything. Your current version becomes another revision, so you can switch back if you change your mind.

If you do not see a Revisions entry, the post has no saved revisions yet, or revisions are disabled on your site.

Restoring only part of a revision

Sometimes you want one paragraph from an old version, not the whole thing. In that case, open the revisions screen, copy the text you need from the older version, close it, and paste it into the current post.

Why revisions can bloat your database

Every revision is a full copy of the post's content. A long post edited dozens of times can have dozens of stored copies. On a site with hundreds of posts, that can add up to tens of thousands of rows in wp_posts.

Revisions rarely slow down a normal site by themselves, since WordPress does not load them on the front end. But a bloated database makes backups larger, migrations slower and some admin queries heavier. Keeping revisions under control is good housekeeping.

How to limit WordPress revisions

By default, WordPress keeps an unlimited number of revisions. You can set a limit by adding a line to wp-config.php, above /* That's all, stop editing! */:

define( 'WP_POST_REVISIONS', 10 );

This keeps the 10 most recent revisions per post. When a new one is saved, the oldest is removed. Between 5 and 20 is a sensible range for most sites.

To disable revisions entirely:

define( 'WP_POST_REVISIONS', false );

That is rarely a good idea. Revisions are your safety net, and a small limit gives you most of the benefit with little database cost.

Note that the limit applies going forward. Existing revisions beyond the limit are trimmed only when that post is saved again.

How to change the autosave interval

To change how often autosave runs, add this to wp-config.php:

define( 'AUTOSAVE_INTERVAL', 120 );

The value is in seconds. Raising it slightly reduces background requests on a busy multi-author site, but means you could lose a little more work in a crash. For most people the default is fine.

How to clean up old revisions

Back up your database before any cleanup. Deleted revisions cannot be recovered.

With a plugin

Database cleanup plugins such as WP-Optimize or Advanced Database Cleaner can delete all revisions, or only those older than a certain age. Run the cleanup, then remove or deactivate the plugin if you do not need it ongoing.

With WP-CLI

If you have SSH access and WP-CLI installed, you can list revisions with:

wp post list --post_type=revision --format=count

and delete them with:

wp post delete $(wp post list --post_type=revision --format=ids) --force

On very large sites, delete in batches to avoid timeouts.

Avoid raw SQL deletes

You may find SQL queries online that delete revisions directly. They can leave orphaned data behind in related tables. A plugin or WP-CLI handles the cleanup through WordPress itself, which is safer.

Good habits around revisions

  • Save drafts deliberately at key points, such as before a big rewrite, so there is a clear version to return to.
  • Use a revision limit rather than disabling revisions.
  • Clean up once or twice a year, especially before a migration.
  • Keep regular backups. Revisions protect content, not your theme, plugins, media or settings.

Wrap-up

WordPress revisions store earlier versions of your posts every time you save, and autosave protects your work in progress every minute or so. Use the Revisions screen to compare and restore versions, set WP_POST_REVISIONS to a sensible number to keep the database lean, and clean up old revisions with a plugin or WP-CLI after taking a backup. It is a small bit of setup that can save you from losing hours of writing.