How to Easily Limit Revisions in WordPress


Table of Contents:



Last updated February 17th, 2025 02:01

Revisions in WordPress are automatically saved versions of posts and pages that allow you to revert to previous content versions. Every edit to a post or page creates a new revision, which can be useful when you want to go back to content before editing. However, problems with revisions can arise when there are many of them on the site, often numbering in the hundreds or even thousands, especially on websites with a large number of posts. Blogs are particularly affected by this. With a high number of revisions, you may notice slower website responses and a noticeable system slowdown. Therefore, it’s good to not only delete revisions from time to time but also limit their number.

In this article, I’ll show you how to easily adjust the number of revisions using a short PHP code and the WP Code plugin.

Installing the WP Code Plugin

To add code to your website, you have two options: You can hard-code it into the appropriate file, or you can use a plugin that inserts the code dynamically. The second option is better for one simple reason: It’s safer, and the code won’t be erased with each update that overwrites your code file.

To install the WP Code plugin:

  • Click on “Plugins” in the left menu.
  • In the submenu, select “Add New.”
  • Notice the search box in the top right corner.
  • Type “WP Code” into the search box.
  • Once WordPress finds the plugin, install and activate it.

If you’re interested in a full article explaining how to work with this plugin, take a look here: How to Insert Custom Code into WordPress.

wpcode

How to Easily Limit Revisions in WordPress

Now that you have the WP Code plugin installed, a new item called “Code Snippets” will appear in the left menu. Click on it and select “+ Add Snippet” from the menu. In the next screen, click on “Add Your Custom Code (New Snippet)”. First, give your snippet a name, and then choose the code language. The snippet will be written in PHP.

wp code vložení snippetu
wp code vložení snippetu
wp code vložení snippetu

In the code editor, insert the following PHP code. The number 20 in the code specifies the maximum number of revisions that WordPress will create. Older revisions beyond this limit will be deleted.

				
					add_filter( 'wp_revisions_to_keep', function( $limit ) {
	// Limit to the last 20 revisions. Change 20 to whatever limit you want.
	return 20;
} );
				
			

Revisions in WordPress – Conclusion

Limiting revisions in WordPress is an important step for optimizing website performance and reducing database load. As we’ve demonstrated, you can limit revisions using a simple PHP code and the WPCode plugin, which allows you to add modifications without manually editing the code.

Adjusting the number of revisions helps keep the database clean, speeds up page loading, and improves overall website performance.

The website is created with care for the included information. I strive to provide high-quality and useful content that helps or inspires others. If you are satisfied with my work and would like to support me, you can do so through simple options.

Byl pro Vás tento článek užitečný?

Klikni na počet hvězd pro hlasování.

Průměrné hodnocení. 0 / 5. Počet hlasování: 0

Zatím nehodnoceno! Buďte první

Jak užitečný vidíte tento článek.

Sledujte mě na sociálních médiích.

Je mi líto, že pro Vás nebyl článek užitečný.

Jak mohu vylepšit článek?

Řekněte mi, jak jej mohu zlepšit.

newsletter

Subscribe to the Newsletter

Stay informed! Join our newsletter subscription and be the first to receive the latest information directly to your email inbox. Follow updates, exclusive events, and inspiring content, all delivered straight to your email.

Odebírat
Upozornit na
guest
0 Komentáře/ů
Nejstarší
Nejnovější Nejvíce hlasováno
Vložené zpětné vazby.
Zobrazit všechny komentáře.

Pokud mi chcete napsat rychlou zprávu, využije, prosím, níže uvedený
kontaktní formulář. Děkuji.

Další Kontaktní údaje