# Limit Post Revisions

> Keeps only the five most recent revisions of each post, which stops the database from growing with old copies.

- Type: PHP
- Runs: Run everywhere
- Category: [Performance](https://wpide.com/library/category/performance/)
- Tags: performance, revisions, database
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/limit-post-revisions/

## Code

```php
add_filter( 'wp_revisions_to_keep', function ( $num, $post ) {
    return 5;
}, 10, 2 );
```

## Notes

Return 0 to disable revisions or -1 to keep all. Existing extra revisions are removed the next time a post is saved.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Limit Post Revisions" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
