Skip to content

Limit Post Revisions code snippet

Watch tutorial on Youtube.

WordPress stores unlimited number of previous versions for each post and page. It is called post revisions. This inflates your database with too many revisions.

Imagine having 100 blog posts and 10k revisions. Your website will slow down because of too many revisions stored in database. Huge database size may slow down every page of your WordPress website.

You can limit number of post revisions so you can still revert back some of the recent content changes.

Code Snippet

add_filter( 'wp_revisions_to_keep', 'veppa_revisions_to_keep', 10, 2 );
function veppa_revisions_to_keep( $num, $post ){
	// 0 — no 
	// -1 — unlimited
	// number of revisions for example 5
	return 5;
}

This snippet sets maximum number of revisions to 5. You can set your own limit.

FAQ

Why unlimited revisions bad?

Unlimited Revisions under each WordPress post.

Imagine blog with 100 posts having around 100 revisions for each post. It makes 10,000 post revisions. Requesting data from database with 10k records uses more server memory and processing power than requesting data from database table with 500 records.

Limiting number of records in database will keep database size small and WordPress website fast.

Why revisions are not limited by default?

WordPress is designed to be flexible. You can enhance it’s features using plugins and code snippets. This code snippet helps to limit number of revisions in WordPress.

What is the use of revisions?

Post revisions will act as a backup of previous version of your post. If you have made a mistake or by accident removed some content from your page then you can revert to previously saved version using post revision.

Having 5 revisions means you can go back to up 5 previous versions for each post.

What is next:

Leave a Reply

Your email address will not be published. Required fields are marked *