How to disable and remove revisions (revisions) in WordPress. The functionality of the history of changes (revisions) in WordPress: how to work with it How to delete old revisions of posts in wordpress

The WordPress changelog is a handy feature that exists in WordPress. It was appreciated by content authors who regularly publish their materials. Often in the process of editing a record, you can make random mistakes or typos. For example, you accidentally deleted part of your post. It is possible to revert it: thanks to revisions, you can always revert to one of the versions of the record.

In this article, we'll show you how the WordPress changelog functionality works, what types of content you can use it with, and how to get the most out of it.

WordPress changelog: what it is

Did you know that WordPress automatically saves all changes you make to posts. You can undo these changes and revert to an earlier version at any time. This functionality is called revisions (versions). It was introduced back in WordPress 2.6.

Thanks to this feature, WordPress will save a post as a revision whenever you click on the “Save as Draft” button or during every automatic save of a post. The autosave feature is activated every 60 seconds - this is a special revision that is superseded by new autosave versions.

It is worth noting that only one autosave is available for any given post. The auto-save feature is especially useful in situations when your browser crashes or your power goes out. In this case, if you go back to editing the post, WordPress will show you a notification that you have a backup of your post along with a link to restore the content.

How to manage change history in WordPress

As you can see from the screenshot below, the revisions are located in the Publish section of the post edit screen. You can also display revisions in the post editor by clicking Screen Options and selecting Revisions.

If you follow the Browse link, you will be taken to the Revisions page. Here you can see the changes specific to each version - use the slider at the top of the screen to do this. You can also use the Previous and Next buttons. There is functionality for comparing two revisions. The window will indicate what has been added, what has remained unchanged, and what has been removed.

What you can do with revisions: You can either restore the revision or leave the entry as is. If you want to restore a specific revision, you can do so by clicking the Restore this revision button. The Return to post editor link will allow you to return to your post without making any changes.

What types of content do revisions support?

WordPress changelog works for all posts and pages on your site, as well as custom post types like Portfolio and Testimonials (added by Jetpack).

If you are using a theme that has its own set of custom post types (for example, portfolio, employees, recommendations, etc.), versions will not be enabled by default (exception: the theme author added support for them). In this case, you can enable revisions yourself with the following code:

$ supports \u003d array ("title", "editor", "revisions");

The code for custom post types is usually located in the functions.php file. Place the line above above the line that starts with register_post_type.

Now let's take a look at how you can benefit from version history.

Enable or completely disable revisions

By default, the revision functionality is automatically enabled for every WordPress build. If you don't have the Revisions option in the post editor, and you've made changes to your post, then revisions may have been disabled at the configuration level.

You can enable revisions manually by adding the following line to your wp-config.php file:

Define ("WP_POST_REVISIONS", true);

You can also disable revisions completely by setting them to false:

Define ("WP_POST_REVISIONS", false);

Limiting the number of available revisions

If you want to limit the number of revisions available for each post or page, you can do so with the following code in your wp-config.php file:

Define ("WP_POST_REVISIONS", 5);

As a result, you will get a maximum of 5 revisions per entry, except for the autosaved version. This is useful if your hosting is limiting the size of the database or if you think you are not using revisions too often.

Revision control for each record

If you are ready for some additional coding, you can do this to limit the number of revisions for each selected entry. To do this, use the wp_revisions_to_keep filter. This is what the code will look like:

Add_filter ("wp_revisions_to_keep", "filter_function_name", 10, 2); function filter_function_name ($ num, $ post) (return $ num;)

Here we are passing a WP_Post object that represents the target post and the required number of versions.

Revision control plugins

As you can guess, there are many WordPress version control plugins. You can use the following plugins to clean up old revisions and enable them for custom post types. We have selected the highest rated plugins to help improve your WordPress revision control.

Optimize Database After Deleting Revisions

Plugin for cleaning unnecessary revisions and optimizing the database. Main functions:

  • Removing revisions for posts, pages and custom post types.
  • Select the number of revisions to keep.
  • Removing spam comments, unused tags.
  • Removing pingbacks and trackbacks.
  • Optimization of database tables.
  • Etc.

The plugin is multisite compatible. It supports periodic cleaning start.

WP Revisions Control

A simple plugin to customize how many revisions WordPress can save for each post and page. Once you activate the plugin, go to Options - Writing to determine how many revisions to keep for each post type.

A relatively new plugin that improves revision management. WordPress will only save revisions if the title, content, or quote has changed. If you modified the post author or changed the permalinks for the post, this will not create a revision. This is the plus of this plugin.

It adds the following fields to the revision system:

  • The Author
  • Post Date
  • Permalink
  • Post Status
  • Post Password
  • Comment Status
  • Ping Status
  • Post / Page Parent
  • Menu Order

The plugin is very handy for blogs with multiple authors and careful control over revisions in posts.

Another plugin for managing revisions. It allows you to limit the number of revisions for any arbitrary post type.

Other possibilities:

  • Disable revisions.
  • Restricting post revisions for the entire site, for each post type, for each individual post
  • Removing revisions in bulk or individually

By default, WordPress saves all revisions of posts and articles with intermediate saves while editing them. Along with revisions, other information can be saved in the database: their metadata and taxonomy. They are unlikely to have any negative impact on a small site, but over time the database will grow, and revisions in it will take up much more volume than published pages and posts.

Be sure to back up your site files and database before disabling revisions and removing old revisions.

Disable or limit revisions

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

Define ("WP_POST_REVISIONS", false);

In order to limit the number of saved revisions, replace in the added line the word false by a number corresponding to the desired number of revisions to keep. For example, to keep 3 revisions, the added line would 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 have it added like 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 turn off the saving of revisions, then there could already be a lot of them and, if you wish, you can delete the old revisions. To do this, you need to log into the phpMyAdmin application, select the database and go to the SQL tab:

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

Removing metadata

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

and press the "Forward" button.

Removing 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 \u003d "revision" AND post_name LIKE "% revision%");

and press the "Forward" button.

Removing all revisions

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

DELETE FROM wp_posts WHERE post_type \u003d "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 have been deleted from the database.

After creating another WordPress site, I remembered revisions when I almost finished work on the first post. When removed, the following results were obtained:

  • meta data - 0 lines removed;
  • taxonomy - 0 lines removed;
  • revisions - 33 lines removed.

Editing one entry that was not finished yet generated 33 revisions that I didn't need. No meta data and taxonomy associated with revisions has been generated.

Revisions (or revisions) in WordPress have been around for a long time. They allow you to save a backup copy of a post or page with each change, and then view all versions with the ability to restore any of them.

Despite this useful functionality, each revision is actually a copy of the record itself, which is also stored in the database. On large sites with a lot of content, editors can significantly increase the size of the MySQL database.

In this short article, we'll go over several methods to limit the maximum number of revisions per post, as well as to remove all revisions from the WordPress database.

Limiting the number of revisions

By default, WordPress stores all revisions for posts and pages. This can be easily changed using the wp_revisions_to_keep filter in your plugin, or using the WP_POST_REVISIONS constant in the wp-config.php configuration file. For example, if we only need to keep the 5 most recent versions of posts and pages, our plugin will look like this:

/ ** * Plugin Name: My Revisions Config * / function my_revisions_to_keep ($ revisions) (return 5;) add_filter ("wp_revisions_to_keep", "my_revisions_to_keep");

Using the filter, you can also restrict revisions depending on the type of recording. For example, if we need 10 revisions for pages and only 5 revisions for posts (and other types), then our plugin will look like this:

Function my_revisions_to_keep ($ revisions, $ post) (if ("page" \u003d\u003d $ post-\u003e post_type) return 10; else return 5;) add_filter ("wp_revisions_to_keep", "my_revisions_to_keep", 10, 2);

You can also set a restriction using the WP_POST_REVISIONS directive in the WordPress wp-config.php configuration file, but the division into post types using this method will no longer be possible:

Define ("WP_POST_REVISIONS", 5);

How to disable revisions

Using these same methods, you can even opt out of WordPress edits altogether. To do this, you need to set a zero limit:

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

Please note that such disabled revisions will not affect existing revisions. All revisions that existed before the shutdown will remain available, and new revisions will not be created when saved. It is also worth noting that autosaves in WordPress are also revisions and the methods described above do not disable them.

How to remove all revisions

After you have disabled revisions in WordPress, you will most likely want to delete all previously created revisions from the WordPress database. It's easy to do this with a couple of queries in MySQL via the command line or phpMyAdmin interface.

Before deleting all revisions, you must delete their metadata and taxonomy, if any. This can be done using the request:

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

Similar request to remove taxonomy:

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

Finally, remove the revisions themselves:

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

This query will remove all revisions from the WordPress database, excluding autosaves. Before executing any such queries, we recommend that you back up your MySQL database.

We also advise you to consider the Revision Control plugin, which allows you to view and delete revisions in WordPress, as well as provides an interface for setting a limit on the number of revisions for posts and pages.

If you have any problems or questions while managing revisions in WordPress - leave a comment and we will be happy to answer you.

Hello everyone, my dear readers of the site. Not so long ago, we parsed the topic on wordpress. But just the other day I had to add another way to this article. It is 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 old versions of cms wordpress.

Why are post revisions needed?

Post and page revisions are only needed in theory. The point is that they save a backup copy of your article in the 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, you create a copy of your article with your changes. And at any time you can see the list of these copies and choose the most suitable one and restore.

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

On the surface, the opportunity seems very useful. However, you must understand that each such saving is an extra load on the database, because all copies are stored in it.

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

But what if you have not 5 editions, but 10 for each post? By the way, how much do you have, if not a secret? Write about it in the comments pzhlst.

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

How can you limit the number of post revisions?

We already know that all revisions are stored in a database. To change their number, we need a standard “filter” 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, who works for it in new versions of WordPress?

So, let's say we want to leave the option to save revisions, but leave, say, only 3pcs. 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");

With wp_revisions_to_keep, you can also limit the number of copies in different post types. More precisely, in one type - 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 post types.

Function my_revisions_to_keep ($ revisions, $ post) (if ("page" \u003d\u003d $ post-\u003e 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 provide an opportunity to split into post types.

define ("WP_POST_REVISIONS", 3);

How to disable and / or remove 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 thing. Disabling revisions will not affect their existence (already existing) 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 removed by hand through the database.

How to delete all revisions, revisions

So we turned off revisions. We already know that just turning off editorials is not enough. It is necessary to uproot them, delete them manually via MySQL.

Let's start, perhaps. But, before deleting something, make a Backup. 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 \u003d "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 \u003d "revision" AND post_name LIKE "% revision%");

And of course, we delete the revisions themselves (revisions).

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

This MySQL query will delete all the revisions in your database. Except 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 the Word, and then just paste them into the admin panel!

A quick reminder on how to work with MySQL

If you suddenly forgot.

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

Go to phpMyAdmin in your hosting control panel.

Enter your username and password.

We chose the database we need and clicked the SQL button, which is at the top.

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

We enter all the requests there in order.

Don't worry if you see null values, it means that you just didn't use the left post types or taxonomies.

And here is what I got using the last request.

See how my blog became faster after that. It's just a fairy tale!

I'm sure you have the same! Check and write to me later about this.

Plugin for working with post revisions

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

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

Want to get rid of unnecessary junk in your WordPress database? Disable post revisions! If interested, read on.

What are revisions?

When you create a new post or page on the site, then save it, and then edit it several times, the "engine" automatically saves all its versions in its database. They are called revisions.

Why disable revisions in WordPress?

If your site has no more than a dozen entries, then there is nothing to worry about. But if there are more than one hundred of them, it is already worth considering. After all, one article can be corrected several dozen times until it is published. This means that several dozen copies of it will be stored in the database. In principle, on the one hand, this is convenient, since it allows you to view all changes, return some of them, etc. But after the publication is posted on the site, its duplicates are no longer needed.

How to disable revisions in WordPress?

If you are the proud owner of a multifunctional premium plugin, then you will not have to look for any other solutions. One of its functions is to completely disable the creation of revisions. To do this, go to the admin section Clearfy pro and in the tab Additionally activate setting Disable revisions completely.

other methods

Revision Control Plugin

Revision Control is a standalone plugin for managing revisions on a WordPress site. Its main feature is the ability to specify for which post types (Pages or Posts) to prohibit the creation of copies.

So, after installing and activating it, go to the Settings -\u003e Revisions admin panel.

You can disable the creation of revisions for the desired post type. To do this, use the corresponding fields: Posts and Pages. To save all changes, click the Save Changes button.

Disable Post Revision Plugin

Disable Post Revision is a separate plugin that performs only one function - completely disabling the creation of copies of content. To do this, you just need to install and activate it. The main advantage of the plugin is the absence of any settings pages. It starts doing its job immediately upon activation.