Every time you save a post or a page, WordPress stores a copy of it as a revision. It’s a handy safety net, but WordPress keeps all of them by default. On a website with hundreds of posts that have been edited many times, those copies quietly fill up your database. You can tell WordPress to keep only the latest few revisions of each post using the following line. If you want to stop revisions completely, see our guide on how to disable post revisions in WordPress.
Where to place? wp-config.php, above the line that says /* That’s all, stop editing! */.
Usage
- To keep your database smaller and your backups faster.
- On websites where posts are edited often, such as news or documentation websites.
- To keep a few recent versions to go back to, without storing dozens of old copies.
Code
// Keep only the last 5 revisions of each post
define( 'WP_POST_REVISIONS', 5 );
Change 5 to any number you like, or use false to stop saving revisions. Old revisions are not removed right away. WordPress trims them the next time each post is saved.
Explanation
- Just a comment to identify the code.
- Defining the
WP_POST_REVISIONSconstant as5. WordPress then keeps up to five revisions of each post and deletes the oldest one when a new one is saved.