PHP snippet · Performance

Limit post revisions

Caps how many revisions WordPress keeps per post, five by default, so the posts table stops growing without limit. One number to edit.

About this php snippet

By default, WordPress keeps every revision of every post forever. A few hundred regularly edited posts is easily tens of thousands of extra rows, sitting in the same table as your real content and carried along by the queries that read it.

It matters more than it sounds on a page builder site. An Elementor layout lives in post meta, and every revision takes its own copy, so a handful of edits to one heavy page can cost more storage than an entire blog's worth of text posts.

What it does

  • Caps the number of revisions WordPress keeps for each post
  • Applies to every post type that supports revisions
  • One value at the top of the snippet, set to 5 out of the box

Good to know

  • Set it to 0 to switch revisions off entirely, though keeping a handful is usually worth the space
  • This applies going forward. It does not delete the revisions you already have. WordPress trims a post's history down to the new number the next time that post is saved.
  • To clear an existing backlog, resave the posts that matter or run a one-off cleanup
  • Autosaves are separate and are not affected. WordPress keeps one per user regardless of this setting.

More php snippets