Skip to content

WordPress Revisions: How to Restore, Limit and Delete Them

2 min read

Applies to: WordPress 7.1.2 (block editor) and WP-CLI

Every time you save or update a post or page, WordPress keeps the previous version as a revision. While you edit, it also makes an autosave every 60 seconds (the default AUTOSAVE_INTERVAL). Revisions let you go back to an older version, but by default WordPress keeps all of them, which slowly grows the database.

Restore an older version

  1. Open the post or page in the editor.
  2. In the sidebar, on the Post (or Page) tab, find Revisions and click the number next to it.
  3. The editor switches to a revision view: move the slider at the top, or pick a version in the sidebar list.
  4. Click Restore to bring that version back, or Exit to return without changes. The Open classic revisions screen link shows the older side-by-side comparison.

The Revisions row only appears once a post has at least one revision.

Limit how many are kept

Add this to wp-config.php, above the line /* That's all, stop editing! */:

define( 'WP_POST_REVISIONS', 5 );

Or with WP-CLI: wp config set WP_POST_REVISIONS 5 --raw. In our test, a post had 5 revisions; after setting the limit to 3 and saving it again, WordPress deleted the oldest ones and kept 3. The limit is applied to a post the next time it is saved.

define( 'WP_POST_REVISIONS', false ); turns revisions off completely (autosaves still happen). We recommend keeping a few instead.

Delete old revisions with WP-CLI

Back up the database first (wp db export). Then:

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

If there are no revisions, the second command only prints its usage help, because it gets no IDs. Afterwards you can run wp db optimize to reclaim the space.

Without SSH

Database cleanup plugins can remove revisions from the dashboard. Remove the plugin again when you are done if you don’t need it regularly.

More WordPress fixes: critical error or white screen and change the WordPress salts.

Related services

Web hosting

shared hosting on Virtualmin with NVMe storage, free SSL and email.

Managed cPanel VPS

cPanel included; we handle updates, security and monitoring.

Hire an expert

engineers per 15 minutes, per hour or per month, with no contract.

Was this answer helpful?

Still stuck? Open a ticket