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

Marc Wag­ner

April 10, 2023

6 min read|

In this tuto­ri­al we will explain what revi­si­ons are in Word­Press, what they are used for and how to limit them.

What are WordPress revisions? #

Revi­si­ons are older ver­si­ons of posts and pages that you can res­to­re at any time via Word­Press. Revi­si­ons can also be enab­led for Cus­tom Post Types. This set­ting depends on the plug­in / the­me aut­hor. By default, Word­Press crea­tes a new revi­si­on of the respec­ti­ve page every time it is saved. This also appli­es to small chan­ges.

Revisions in the Classic Editor

The indi­vi­du­al revi­si­ons are dis­play­ed when you edit the page. You can also see who edi­ted them and when they were crea­ted.

WordPress revisions example

If you can’t see the revi­si­ons, you should adjust the view. The but­ton for this can be found at the top right cor­ner of the screen.

Side view revisions

Make sure “Revi­si­ons” is che­cked to show the revi­si­ons.

Alter­na­tively, you can find the revi­si­ons in the side­bar in the Publish tab. The­re we will see the num­ber of revi­si­ons (if any). You can also access the res­to­ra­ti­on by cli­cking on the “Show” link.

WordPress revisions in the sidebar of posts and pages.

Revisions in Gutenberg Editor (Block Editor)

In the Block Edi­tor, the revi­si­ons are dis­play­ed in the side­bar. The revi­si­ons are visi­ble as soon as you are in the “Page” tab.

WordPress Revision in Block Editor

By cli­cking on the but­ton (in the pic­tu­re: 2 revi­si­ons) you get to the revi­si­on manage­ment. From the­re you can res­to­re the revi­si­ons.

Why limit revisions? #

Revi­si­ons can have a nega­ti­ve impact on your web­site load times. Each revi­si­on is stored in the data­ba­se. Wit­hout rest­ric­tion, it infla­tes unhin­de­red. Queries to the data­ba­se beco­me slower, the backend of Word­Press some­ti­mes more cum­ber­so­me. Espe­ci­al­ly with lar­ger sites, it can hap­pen that seve­ral hundred revi­si­ons exist for indi­vi­du­al pages or posts.

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

You can set the num­ber of revi­si­ons in wp-config.php. For exam­p­le, to limit the num­ber of revi­si­ons per page/post to 50, just add the fol­lo­wing befo­re the line

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

enter the fol­lo­wing code:

define( 'WP_POST_REVISIONS', 50 );

Just replace the 50 with the num­ber that seems right for your web­site. I always set the value bet­ween 15 and 20 for smal­ler Word­Press web­sites.

Atten­ti­on: The chan­ge does not affect exis­ting revi­si­ons. If your web­site has alre­a­dy crea­ted many revi­si­ons, you will need to remo­ve them manu­al­ly. For this you can eit­her use a plug­in (e.g. WP-Opti­­mi­­ze) or remo­ve the ent­ries direct­ly via SQL. The second vari­ant is some­what more com­plex and is only recom­men­ded for experts.

How can I completely disable revisions in WordPress? #

To com­ple­te­ly disable the revi­si­ons in Word­Press, you just have to add in wp-config.php befo­re the line

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

insert the fol­lo­wing code:

define( 'WP_POST_REVISIONS', false );

With this, Word­Press does not crea­te any fur­ther revi­si­ons. If you are still crea­ting revi­si­ons, you should check if the­re is not alre­a­dy an ent­ry named “WP_POST_REVISIONS” in your wp-config.php. If the ent­ry alre­a­dy exists, you should chan­ge it or remo­ve it.

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

It is pos­si­ble to disable revi­si­ons only for cer­tain post types (posts, pages, cus­tom post types). To do this, we just need to add a small code in functions.php that will do the deac­ti­va­ti­on.

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');

Sim­ply extend the $post_types array with the desi­red post types. This opti­on also works for plug­ins and the­mes.

How can I restore a WordPress revision? #

The­re may be times when you want to undo chan­ges you have made to your Word­Press site. If that’s the case, you can do it quick­ly and easi­ly with Word­Press revi­si­ons.

Just sel­ect the desi­red revi­si­on to compa­re the chan­ges. By default, Word­Press dis­plays the revi­si­ons for a post or page sequen­ti­al­ly. Howe­ver, you can disable this by sel­ec­ting the opti­on Compa­re any two revi­si­ons.

Compare any two revisions in WordPress

Then sel­ect the ver­si­on you want to compa­re the cur­rent sta­te with. As soon as you find the ver­si­on you want to go back to, con­firm it by cli­cking the Res­to­re this revi­si­on but­ton.

image 4

As soon as you press the but­ton, the ver­si­on you are curr­ent­ly com­pa­ring with is auto­ma­ti­cal­ly res­to­red (Right side).

How can I delete WordPress revisions? #

Revi­si­ons can be dele­ted in Word­Press eit­her via a plug­in like WP-Opti­­mi­­ze or via the data­ba­se (SQL).

How to delete revisions with the WP-Optimize plugin

First switch to the set­tings. The­re you have the opti­on to spe­ci­fy how many revi­si­ons you want to keep for pages, posts and cus­tom post types.

image 5

Acti­va­te the Always keep [Anzahl an Revi­sio­nen] post revi­si­ons opti­on. At the same time, spe­ci­fy how many revi­si­ons you want to keep. Con­firm your set­tings by cli­cking the Save Set­tings but­ton.

Atten­ti­on: Befo­re you con­ti­nue, you should crea­te a back­up of your web­site. For this you can use the plug­in Duli­ca­tor. Here you can find ins­truc­tions on how to use Dupli­ca­tor to secu­re your web­site local­ly.

After you have made the set­tings, switch to the Opti­miza­ti­ons tab and click the Exe­cu­te Opti­miza­ti­on but­ton in the Clean post revi­si­ons but keep at least [Anzahl der Revi­sio­nen] revi­si­ons line.

image 6

Dele­ting Word­Press revi­si­ons can take some time, depen­ding on how many ent­ries are in your site.

How to delete your WordPress revisions via SQL in the database

As a deve­lo­per, you can also dele­te revi­si­ons of your Word­Press web­site direct­ly via the data­ba­se. Assum­ing you know your way around it. If you don’t, you’d bet­ter resort to a plug­in solu­ti­on (see abo­ve).

To dele­te revi­si­ons of your Word­Press web­site direct­ly from the data­ba­se, you can sim­ply exe­cu­te the fol­lo­wing MyS­QL query:

DELETE FROM wp_posts WHERE post_type = 'revision';

If you have sel­ec­ted a dif­fe­rent pre­fix(wp_), you need to adjust the state­ment. Plea­se also keep in mind that this will only dele­te the data from the wp_posts table. It may hap­pen that indi­vi­du­al plug­ins addi­tio­nal­ly store meta data or assign terms. The­se must then also be remo­ved.

Summary #

Word­Press revi­si­ons are useful and can save you from losing work. They allow you to res­to­re older ver­si­ons of indi­vi­du­al pages, posts and cus­tom post types. Howe­ver, with lar­ger Word­Press web­sites, revi­si­ons can quick­ly accu­mu­la­te and unneces­s­a­ri­ly bloat your data­ba­se. This can nega­tively affect the per­for­mance of your web­site.

The­re are a num­ber of ways you can use to make sure this does­n’t hap­pen to you:

  1. Limit the num­ber of revi­si­ons for pages and posts in your wp-config.php file.
  2. Dele­te revi­si­ons that are no lon­ger nee­ded with WP-Opti­­mi­­ze or direct­ly via the data­ba­se.
  3. Limit the revi­si­ons to the post types you real­ly need them for.

The per­for­mance of a Word­Press web­site depends on both the ser­ver and the data­ba­se.

88e86fcb816eff22bc917094df2862d8dd5c0e978b333e6dd5f36f808990c261 96

Arti­kel von:

Marc Wag­ner

Hi Marc here. I’m the foun­der of Forge12 Inter­ac­ti­ve and have been pas­sio­na­te about buil­ding web­sites, online stores, appli­ca­ti­ons and SaaS solu­ti­ons for busi­nesses for over 20 years. Befo­re foun­ding the com­pa­ny, I alre­a­dy work­ed in publicly lis­ted com­pa­nies and acqui­red all kinds of know­ledge. Now I want to pass this know­ledge on to my cus­to­mers.

Hast du eine Fra­ge? Hin­ter­lass bit­te einen Kom­men­tar
  1. 225ef299f940478ad4e4e99fc6f056e2ecabede4328e0a4e57581d48a02dc4be 54
    work­time Decem­ber 7, 2023 at 14:44 — Rep­ly

    An excel­lent tuto­ri­al on revi­si­ons. It is very important to under­stand how chan­ges work, espe­ci­al­ly when opti­mi­zing a web­site. Limi­ting the num­ber of revi­si­ons is a smart move to pre­vent data­ba­se bloat and ensu­re fas­ter loa­ding times.