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

Your EMCP guide

Answers from our docs

YOUR CHAT, YOUR CHOICE

Before we chat

MSR Builds processes your question and up to four recent messages on our server to answer from the EMCP docs. AI is optional and needs your separate permission.

The chat is kept in this page's memory, not saved as a conversation in our database or browser storage. Our hosting and security services process connection information, such as your IP address, to prevent abuse.

Cloudflare Turnstile checks your browser and connection to prevent automated abuse when you send a question. No login is required.

Please leave out personal, sensitive or confidential information, passwords and API keys.

You can withdraw consent and clear this page's chat at any time. This cannot undo a request already sent or erase provider/security records.

Chat privacy, retention & your rights ↗ · Privacy contact

Starting chat consents to this processing. You can browse our docs without using the chat.