Managing WordPress Post Revisions: A Comprehensive Guide
This article is a SiteGround partnership contribution. Thank you for supporting our sponsors.
WordPress's revision system automatically saves a complete copy of each page and post upon saving, allowing you to revert to previous versions and compare changes. While helpful, unlimited revisions can impact performance, especially on larger sites. This guide explores various methods for controlling and managing WordPress revisions.
Limiting Revisions
By default, WordPress stores an unlimited number of revisions. To limit this, you can modify the wp-config.php
file. Always back up this file before making any changes.
define('WP_POST_REVISIONS', 0);
to completely disable revisions.define('WP_POST_REVISIONS', 10);
to limit to ten revisions. Replace 10
with your desired number.-1
.Using Plugins for Revision Control
If direct file editing isn't preferred, several plugins offer revision management. WP Revisions Limit
, for example, provides a user-friendly interface for setting revision limits.
Programmatic Revision Control
For more advanced control, the wp_revisions_to_keep
filter allows customization within your theme's functions.php
file or a plugin. This filter accepts two arguments: the default revision count and the WP_Post
object. The following example limits revisions to five for posts of type "custom_post":
add_filter( 'wp_revisions_to_keep', 'control_revisions', 10, 2 ); function control_revisions($num, $post) { if('custom_post' == $post->post_type) $num = 5; return $num; }
The WordPress REST API also offers options for managing revisions.
Removing Old Revisions
While setting WP_POST_REVISIONS
takes immediate effect, it doesn't remove existing revisions. Always back up your database before performing database cleanup.
WP-Optimize
offer database optimization, including revision removal. They provide a safe and convenient method.wp_
in wp-config.php
), execute this SQL command in a MySQL administration tool like phpMyAdmin:DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id ) LEFT JOIN wp_postmeta c ON ( a.ID = c.post_id ) LEFT JOIN wp_term_taxonomy d ON ( b.term_taxonomy_id = d.term_taxonomy_id ) WHERE a.post_type = 'revision' AND d.taxonomy != 'link_category';
(Credit to Michael Ambrosio for providing this refined SQL command.)
Frequently Asked Questions
This section answers common questions about WordPress revision control, covering topics such as limiting revision numbers, completely disabling revisions, deleting old revisions, the difference between autosave and revisions, restoring previous versions, comparing revisions, using revisions with custom post types, identifying revision authors, performance impact, and using plugins for revision management. (The original FAQ section is incorporated here but reformatted for better readability and flow.)
Remember to always back up your files and database before making any significant changes to your WordPress installation.
The above is the detailed content of How to Take Control of Page and Post Revisions in WordPress. For more information, please follow other related articles on the PHP Chinese website!