How to remove revisions in wordpress. How to disable, limit, delete WordPress revisions. We limit the number of available revisions

Good afternoon everyone. Today I wrote for you a purely technical article that allows you to optimize your WordPress blog database by cleaning revisions (automatically saved copies of articles). We will take a detailed look at and analyze the purpose of revisions, their essence, and I will also show you how to delete and disable or limit the appearance of revisions in WordPress. The material published below will be accompanied by detailed pictures with comments.

As you can see, there are quite a lot of questions to study. True, for many owners of Internet resources it will not be new, but the “smartest” do not read my blog, it is read by those who want to learn. To create a popular, reliable and stable website, beginners need to understand all the technical intricacies and have a practical understanding of revisions and much more. Will learn.

What are revisions in WordPress

Perhaps you have noticed that while writing or editing a post, the system automatically makes a copy of it - a backup save. At this time, the “Publish” and “Save” buttons located in the window on the right become inactive. This action is called revision.

Revisions in WordPress are an automatic backup of the contents of a post or page to prevent data loss. From them you can restore earlier copies of documents.

Many people have probably guessed that WordPress revisions are used to avoid data loss. They are configured automatically and make a backup copy after a certain period of time (every 60 seconds). They are added to a database (MySql - phpMyAdmin). You can view the list of revisions in WordPress just below the post edit window (in edit mode). If you scroll the page, you can see them just below in the “Editors” window. They look like this:

You probably already have the question “Why delete or disable revisions?” if they play such a useful role. The whole problem is that copies of records, articles or posts greatly load the database into which they are entered. This leads not only to the future problem of editing and making changes, but also to slow loading of site pages. I advise you to read the post "". Search engines began to pay special attention to this parameter. Also, by the way, the behavioral factor directly depends on this, the indicator of which is formed from an assessment of user behavior.

Naturally, we need to get rid of revisions, no matter how useful they may be. This will not only reduce the size and volume of the database, but also load the site much faster.

How to Delete Revisions in WordPress

There are different ways to delete revisions, I will show two. One is aimed at dummies, such as I was recently, and the second at people who are more prepared (who are not afraid of servers and databases).

Method number 1. Better Delete Revision plugin

We will use a specially created plugin for deleting revisions - Better Delete Revision. Download it via Admika and install it. After activation, an item with a name similar to the name of the plugin will appear in the settings section - these are settings.

You can immediately optimize the database or go to the “Check revision records” tab and from there clean your blog from unnecessary copies of documents.

Method No. 2.Deleting directly from the database

This one is a little more difficult to implement. I don't want to scare you, but if you are afraid of doing something wrong, then it is better to skip it. In this method, we will delete copies of articles directly through the database itself. Just before going there, I advise you to make a copy of it. If you don't know how to do this, then read the post.

After selecting the desired database, find the “SQL” tab, open it so that an empty field appears in front of you.

You need to copy the code below into it and click on the “OK” button. With this action you will make an SQL request to delete revisions from the database.

DELETE FROM wp_posts WHERE post_type = "revision";

It should look like the picture:

If your actions are successful, you will see a message like the following in response. If you have not previously deleted or disabled revisions, then the number of lines will be different from zero.

How to Disable WordPress Revisions

In order not to waste time on cleaning each time, the creation of backup copies of articles can be disabled. Then your “Editors” window will simply disappear and permanent saving will stop happening. Please think very carefully before doing this, as you will no longer be able to open or return to the previous version of the entry.

To disable revisions, you need to go to your hosting and edit the wp-config.php file, which is located in the root folder. Paste the code with the parameter into it:

Define("WP_POST_REVISIONS", 3);

The number sets the number of document versions that will be stored in the database. Limit it to the number you need, for example one would mean you have one published and one backed up (last edited).

After finishing making changes, click on the “Save” button. Now your database will not swell like yeast dough every time you edit articles.

This is where I end this post. I hope this information was useful to you. If you have any questions, please leave them in the comments.

By default, WordPress saves all revisions of posts and articles during intermediate saves during the editing process. Along with revisions, other information can be saved in the database: their metadata and taxonomy. It is unlikely that they can have any negative impact on a small site, but over time the database will grow, and the revisions in it will occupy a much larger volume than the published pages and posts.

Before disabling revisions and deleting old editions, be sure to back up your site files and database.

Disabling or limiting revisions

Saving post and page revisions in the WordPress site database can be disabled or limited in number. To do this you need to open the file wp-config.php and, to disable saving revisions completely, add the line:

Define("WP_POST_REVISIONS", false);

In order to limit the number of saved revisions, replace the word in the added line false by a number corresponding to the desired number of saved revisions. For example, to save 3 revisions, the added line will look like this:

Define("WP_POST_REVISIONS", 3);

Number 0 in this expression will match the keyword false.

Please note that the added line must be placed in the wp-config.php file after the line:

Define("WP_DEBUG", false);

and before the line:

I added this:

Define("WP_DEBUG", false); /* Cancel or limit the number of revisions */ define("WP_POST_REVISIONS", false); /* That's all, no further editing. Good luck! */

Removing all old revisions

If you did not immediately disable saving revisions, then there might already be quite a lot of them and, if desired, old revisions can be deleted. To do this, you need to log into the phpMyAdmin application, select a database and go to the SQL tab:

Before deleting all revisions from your WordPress site's database, you must first remove their metadata and taxonomy, if any. Copy and paste the following three commands into the input field one by one and click the “Forward” button. If you specified a prefix other than “wp_” for your database tables when installing WordPress, replace “wp_” in the commands below with your prefix.

Removing Meta Data

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%");

and press the “Forward” button.

Removing a taxonomy

copy and paste the following line into the SQL query input field:

DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%");

and press the “Forward” button.

Delete all revisions

copy and paste the following line into the SQL query input field:

DELETE FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%";

and press the “Forward” button.

After executing each command, you will see in the information window how many rows were deleted from the database.

After creating another website on WordPress, I remembered about revisions when I was almost finished working on the first post. When deleting, the following results were obtained:

  • meta data - 0 rows removed;
  • taxonomy - 0 rows removed;
  • revision - 33 lines were deleted.

Editing one post, which was not yet completed, created 33 revisions that I didn't need. No metadata or taxonomy associated with revisions was created.

What are WordPress revisions and why are they needed?

Audits– this is a backup saving of a post (post) in WordPress, which is performed automatically by the engine.

I think you have seen that when publishing a new post on a blog, in the admin panel, when editing a post, the “Publish” button becomes inactive from time to time. So, just at this moment wordpress performs an audit.

That is, in other words, if you edit a post in the admin panel, WordPress saves the old copy of this post to its database so that you can return to it at any time. He performs such saves once every 60 seconds. (this is the default, but you can set it to any time).

As you may have guessed, this is done for the purpose of protecting you from unexpected data loss. After all, no one is immune from force majeure; for example, I had a case when, when publishing a post, my browser closed by itself for some reason, and after starting it showed me a message about a fatal error. And naturally, in this case, all the sites that were in the tabs were closed, and accordingly all the information was lost. It is precisely in such situations that the revisions that WordPress makes save the day.

By the way, you can see the list of all revisions in the same place - in the WordPress admin panel. They are located just below the entry you are editing:

Here you may have a question: since revisions are so useful, why should they be deleted? Let me explain.

The fact is that such backup copies of posts significantly bloat the database; they, one might say, clog it with unnecessary garbage that needs to be gotten rid of. After all, think for yourself, when you need to make a lot of changes to a post, you edit it, and at the same time Wordpress saves old copies of posts one after another. These copies are added to the base and increase its size. But if you look at it like this, then we essentially don’t need them, well, maybe the last 2-3 copies, but not the rest. Therefore, naturally, you need to get rid of such things, in this case the database will become lighter and WordPress will work faster.

Removing wordpress revisions

Now there are several ways to delete revisions. You can delete backups manually, directly in the database, by entering a special SQL query, or you can perform this operation using specialized plugins. We will now consider all these methods.

First way– SQL query to the database. The first thing I recommend is to back up your database, in case you do something wrong, so that you can quickly restore all your data.

So, go to phpMyAdmin on the hosting, select the database for which you want to clear revisions.

After that, in the top panel, go to the SQL tab and insert this entry into the field that appears:

DELETE FROM wp_posts WHERE post_type = “revision”;

Database Query

If you do everything correctly, an inscription will appear in front of you, which will signal that revisions have been successfully deleted from the database. Message about successful execution of SQL query

Second way– We use the plugin Revision Control. Everything is simple here, first download the plugin, then install it. Installation field in the “Tools” panel, you will have another section - “ Revision Control", the plugin is very simple and I think it won’t be difficult for you to understand it.

That's all, the revisions have been deleted!!!

These are the two most basic ways to clear a database of revisions. There are, of course, several more plugins that allow you to perform this manipulation (more specifically, this is DelRevision And WP_Optimize) but I think that these two methods will be enough for you.

I would also like to say that you also have the opportunity to completely prohibit WordPress from making revisions. The truth here is that you should always keep in mind that in cases of force majeure, you will not be able to recover lost data.

In order to prohibit backup data storage, you need to perform a number of actions, namely:

Go to the hosting file manager (or contact the hosting via an FTP client).

Find a folder on the server wp-includes(This is usually located in the root directory of your site /yoursite/wp-includes.)

In folder wp-includes find file default-constants.php and open it in a text editor.

In this file find the inscription:

define('WP_POST_REVISIONS', true);

And replace it with:

define('WP_POST_REVISIONS', false);

That's it, after this WordPress revisions will be disabled!

Hello everyone, my dear readers of the site. Not long ago we looked at a WordPress theme. But just the other day I had to add one more method to this article. Extremely effective when you have been blogging for a long time, provided that you did not know this trick.

These so-called revisions or, in other words, editions have existed since older versions of cms Wordpress.

Why are post revisions needed?

Revisions of posts and pages are needed only in theory. The point is that they save a backup copy of your article in a database. Moreover, saving occurs every time you change.

It turns out that in the process of writing an article, when you click the “Save” button, a copy of your article is created with your changes. And at any time you can look at the list of these copies and select the most suitable one and restore it.

In all my practice, I have only had to restore a copy from such reserves once. But nonetheless.

On the face of it, the feature seems quite useful. However, you must understand that each such save is an extra load on the database, because all copies are stored there.

Here's an example from life. On average, I had 4-5 revisions of each article on my blog. Imagine when you have hundreds of articles written, and perhaps thousands of articles - by removing revisions (editions) of posts - you will thereby speed up your blog by 5 times.

What if you don’t have 5 revisions, but 10 for each post? By the way, how much do you have, if it’s not a secret? Write about it in the comments please.

By the way, the most interesting thing is that when you don’t even click on the “Save” button, post revisions are created automatically. This is called autosave.

How can I limit the number of post edits?

We already know that all revisions are stored in a database. To change their number, we need a standard “filter”, which is called wp_revisions_to_keep, or using the WP_POST_REVISIONS directive in the wp-config.php file.

By the way, for some reason the directive in the wp-config file did not work for me. Write, for whom does it work in new versions of WordPress?

So, let's say we want to leave the ability to save revisions, but leave, say, only 3 pieces. To do this we need to write the following:

Function my_revisions_to_keep($revisions) ( return 3; ) add_filter("wp_revisions_to_keep", "my_revisions_to_keep");

Using wp_revisions_to_keep you can also limit the number of copies in different post types. More precisely, in one type there is one number of revisions, in another - another.

Well, for example, let’s say you need 5 revisions for pages and 3 revisions for articles (posts) and other types of posts.

Function my_revisions_to_keep($revisions, $post) ( if ("page" == $post->post_type) return 5; else return 3; ) add_filter("wp_revisions_to_keep", "my_revisions_to_keep", 5, 2);

You can also try using WP_POST_REVISIONS in the wp-config.php file, but this method does not allow you to separate post types.

define("WP_POST_REVISIONS", 3);

How to disable and/or delete revisions in wordpress

In the same way, you can refuse revisions altogether. You just need to put the number 0 in the restrictions.

Function my_revisions_to_keep($revisions) ( return 0; ) add_filter("wp_revisions_to_keep", "my_revisions_to_keep");

Or using the wp-config.php file:

Define("WP_POST_REVISIONS", 0);

The most important. Disabling revisions will not affect their existence (already existing ones) in any way. those. if you had 3-5 revisions for each article and you disabled revisions, old copies of posts will still remain. They need to be deleted manually through the database.

How to delete all revisions and editions

So, we disabled the editors. WE already know that simply disabling editors is not enough. You need to uproot them and delete them manually via MySQL.

Let's get started, I guess. But before you delete anything, make a backup. It's better to make a backup of the entire site.

DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%");

We do something similar for taxonomies

DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%");

And of course, we delete the revisions themselves.

DELETE FROM wp_posts WHERE post_type = "revision" AND post_name LIKE "%revision%";

This MySQL query will delete all revisions in your database. Except for autosaves.

Autosave is also considered a revision, but they are not deleted or disabled!! Therefore, to keep them as small as possible, write the texts in advance in Word, and then simply paste them into the admin area!

A little reminder on how to work with MySQL

In case you forgot.

I work with adminvps hosting, I even told you why in this article. So, I will show everything on it.

Login to phpMyAdmin in your hosting control panel.

Enter your login and password.

We selected the database we needed and clicked the SQL button, which is located at the top.

And we see a large field for writing SQL queries. For the entire Database.

There we enter all requests in order.

Don't worry if you see zero values, it means you simply didn't use left post types or taxonomies.

And this is what I got using the last request.

Look how my blog became faster after this. It's just a fairy tale!

I'm sure you have the same thing! Check it out and write me back about it later.

Plugin for working with post editors

I can also recommend the Revision Control plugin, it allows you to do the same thing as I described, only in a more comfortable mode for you. Right in the admin panel.

If you still have questions, ask, I will be happy to help you. That's all for now. Thank you for your attention.

Saving changes to posts can be very useful when working in WordPress. If something goes wrong and you lose information from a post, you can always access a previous saved version of your post by simply clicking on the link in the menu Editorial under the editor window.

Many, many revisions

If you've been working with WordPress for a while, then you've undoubtedly used this feature once or twice. But you've probably noticed that these changes tend to accumulate.

If you write a post in the editor, then WordPress saves the revisions automatically when you save the post. As a result, it is not uncommon to have more than 20 edits to a post. Multiply this by the number of posts on your site, and you get megabytes of additional posts stored in the database.

How to get rid of old editions

Some people don't like keeping all those old versions in their database. They believe that they are slowing down their site. This, however, is a myth.

WordPress developer Mike Little responded in a comment on WPBeginner, "WordPress queries to the database do not receive revisions, so the number of revisions does not affect the speed of the queries. The only time revisions are loaded on the page is when editing an individual post. And this does not affect page loading speed of your site."

However, many people still believe that having a small and lightweight database is a very good thing, and therefore they still prefer to get rid of their old revisions.

If you are one of them, then one of the three plugins below will help you do this.

1. Better Delete Revision

Better Delete Revision deletes old versions of posts and also optimizes your database.

The plugin page states: "By optimizing and deleting old editions, this plugin will make your database lighter and smaller over the course of its use. Removing old editions and optimizing databases is one of the best things you can do to keep your The blog worked as quickly as possible."

Take a look at the plugin settings page as well as the uninstallation process.

Plugin differs from Better Delete Revision in that it does not bulk delete your revisions, however, it will give you two features that Better Delete Revision does not have.

It allows you to first determine how many revisions have been saved.

And it allows you to delete individual revisions on the edit page.

3. Revision Cleaner

Plugin Revision Cleaner allows each user to set a time interval for automatic deletion of his revisions. This can be done on the user profile page.