WordPress Revisions: How to use and optimize them on your website (Tutorial, 2023)

In this tutorial we will explain what revisions are in WordPress, what they are used for and how to limit them.

What are WordPress revisions? #

Revisions are older versions of posts and pages that you can restore at any time via WordPress. Revisions can also be enabled for Custom Post Types. This setting depends on the plugin / theme author. By default, WordPress creates a new revision of the respective page every time it is saved. This also applies to small changes.

Revisions in the Classic Editor #

The individual revisions are displayed when you edit the page. You can also see who edited them and when they were created.

WordPress revisions example

If you can’t see the revisions, you should adjust the view. The button for this can be found at the top right corner of the screen.

Side view revisions

Make sure “Revisions” is checked to show the revisions.

Alternatively, you can find the revisions in the sidebar in the Publish tab. There we will see the number of revisions (if any). You can also access the restoration by clicking on the “Show” link.

WordPress revisions in the sidebar of posts and pages.

Revisions in Gutenberg Editor (Block Editor) #

In the Block Editor, the revisions are displayed in the sidebar. The revisions are visible as soon as you are in the “Page” tab.

WordPress Revision in Block Editor

By clicking on the button (in the picture: 2 revisions) you get to the revision management. From there you can restore the revisions.

Why limit revisions? #

Revisions can have a negative impact on your website load times. Each revision is stored in the database. Without restriction, it inflates unhindered. Queries to the database become slower, the backend of WordPress sometimes more cumbersome. Especially with larger sites, it can happen that several hundred revisions exist for individual pages or posts.

How can I limit the number of revisions for posts, pages and images? #

You can set the number of revisions in wp-config.php. For example, to limit the number of revisions per page/post to 50, just add the following before the line

/* Add any custom values between this line and the "stop editing" line. */

enter the following code:

define( 'WP_POST_REVISIONS', 50 );

Just replace the 50 with the number that seems right for your website. I always set the value between 15 and 20 for smaller WordPress websites.

Attention: The change does not affect existing revisions. If your website has already created many revisions, you will need to remove them manually. For this you can either use a plugin (e.g. WP-Optimize) or remove the entries directly via SQL. The second variant is somewhat more complex and is only recommended for experts.

How can I completely disable revisions in WordPress? #

To completely disable the revisions in WordPress, you just have to add in wp-config.php before the line

/* Add any custom values between this line and the "stop editing" line. */

insert the following code:

define( 'WP_POST_REVISIONS', false );

With this, WordPress does not create any further revisions. If you are still creating revisions, you should check if there is not already an entry named “WP_POST_REVISIONS” in your wp-config.php. If the entry already exists, you should change it or remove it.

How can I disable WordPress revisions for individual post types? #

It is possible to disable revisions only for certain post types (posts, pages, custom post types). To do this, we just need to add a small code in functions.php that will do the deactivation.

function disable_revisions_for_post_type() {
	$post_types = ['portfolio', 'post', 'page'];

	foreach($post_types as $post_type){
		remove_post_type_support( $post_type, 'revisions' );
	}
}

add_action('admin_init', 'disable_revisions_for_post_type');

Simply extend the $post_types array with the desired post types. This option also works for plugins and themes.

How can I restore a WordPress revision? #

There may be times when you want to undo changes you have made to your WordPress site. If that’s the case, you can do it quickly and easily with WordPress revisions.

Just select the desired revision to compare the changes. By default, WordPress displays the revisions for a post or page sequentially. However, you can disable this by selecting the option Compare any two revisions.

Compare any two revisions in WordPress

Then select the version you want to compare the current state with. As soon as you find the version you want to go back to, confirm it by clicking the Restore this revision button.

image 4

As soon as you press the button, the version you are currently comparing with is automatically restored (Right side).

How can I delete WordPress revisions? #

Revisions can be deleted in WordPress either via a plugin like WP-Optimize or via the database (SQL).

How to delete revisions with the WP-Optimize plugin #

First switch to the settings. There you have the option to specify how many revisions you want to keep for pages, posts and custom post types.

image 5

Activate the Always keep [Anzahl an Revisionen] post revisions option. At the same time, specify how many revisions you want to keep. Confirm your settings by clicking the Save Settings button.

Attention: Before you continue, you should create a backup of your website. For this you can use the plugin Dulicator. Here you can find instructions on how to use Duplicator to secure your website locally.

After you have made the settings, switch to the Optimizations tab and click the Execute Optimization button in the Clean post revisions but keep at least [Anzahl der Revisionen] revisions line.

image 6

Deleting WordPress revisions can take some time, depending on how many entries are in your site.

How to delete your WordPress revisions via SQL in the database #

As a developer, you can also delete revisions of your WordPress website directly via the database. Assuming you know your way around it. If you don’t, you’d better resort to a plugin solution (see above).

To delete revisions of your WordPress website directly from the database, you can simply execute the following MySQL query:

DELETE FROM wp_posts WHERE post_type = 'revision';

If you have selected a different prefix(wp_), you need to adjust the statement. Please also keep in mind that this will only delete the data from the wp_posts table. It may happen that individual plugins additionally store meta data or assign terms. These must then also be removed.

Summary #

WordPress revisions are useful and can save you from losing work. They allow you to restore older versions of individual pages, posts and custom post types. However, with larger WordPress websites, revisions can quickly accumulate and unnecessarily bloat your database. This can negatively affect the performance of your website.

There are a number of ways you can use to make sure this doesn’t happen to you:

  1. Limit the number of revisions for pages and posts in your wp-config.php file.
  2. Delete revisions that are no longer needed with WP-Optimize or directly via the database.
  3. Limit the revisions to the post types you really need them for.

The performance of a WordPress website depends on both the server and the database.

Hier klicken, um den Beitrag zu bewerten
[Gesamt: 0 Durchschnitt: 0]

One Comment

  1. Avatar of worktime
    worktime December 7, 2023 at 14:44 - Reply

    An excellent tutorial on revisions. It is very important to understand how changes work, especially when optimizing a website. Limiting the number of revisions is a smart move to prevent database bloat and ensure faster loading times.

Leave A Comment

Title