If you’re familiar with wiki software such as MediaWiki or DokuWiki, you’re probably aware that most wiki software keeps a copy of every single revision made to a wiki article. If you’re not familiar with that feature, go to any random article on Wikipedia (which runs on MediaWiki), and click on the “View History” tab to see a list of prior revisions:
Pretty cool, huh?
What most people don’t know is that WordPress has a similar function called post revisions. It also keeps track of every single change you make you to a post. You can see it in the “Publish” box:
Click on that link and you’ll see something like this:
I’m not going to get into the details of how to view various versions because the controls on that page are fairly self-explanatory.
I don’t find post revisions very useful, as most of my posts tend to be “once and done” things, with minimal editing thereafter, mostly for typos, because I do first drafts (and sometimes second and third drafts) on paper first. As a result, I usually disable post revisions on my WordPress installs. However, if you find them useful, they are well-running parts of WordPress core (hence, no plugin needed) and easy to manage.
You should know a few things about post revisions, however.
- Post revisions are automatically enabled in a default WordPress install.
- You can turn them off, but this involves editing
wp-config.phpwhich is why I’ve labeled this post as intermediate level. The easiest way to do that is to download the file via SFTP, edit the file in a text editor, and then upload it to your site, overwriting the version you downloaded. (You can also do this via the shell—bonus points!)
- The default setting is to keep track of every revision. You can also limit how many revisions to keep, but again, this also involves editing
- Post revisions can really bloat the size of your database. Every time you click that “Save Draft” or “Publish” button on a post, you’re adding another revision to the database. (I recently cleared out old post revisions on a WordPress install and cut the database size down to a third of what it formerly was.)
- You can clear old revisions out of the database with a MySQL query.
In this article, I will show you how to do all those things.
Turn Off Post Revisions
Like I said, you will need to edit
wp-config.php for this one. Add the following line:
define('WP_POST_REVISIONS', false );
Also, make sure that you add this line above the one that reads:
/* That's all, stop editing! Happy blogging. */
This will turn off all future post revisions, but all previous post revisions will remain in your database. If you’ve been blogging for a while, you will probably want to clear those out.
Limit Post Revisions
You can also limit the number of post revisions WordPress will save. Edit
wp-config.php and add the following line:
define('WP_POST_REVISIONS', 5 );
The above line will limit WordPress to five post revisions. You can change that to whatever value works for you. (And again, remember that if you have posts with more than 5 post revisions, those are still stored in the database.)
Delete Old Post Revisions From the Database
Neither of the above options will remove existing post revisions from your database, however. If you decide that you don’t need post revisions, and you turn them off, you’re still storing them in your database and still backing them up when you back up your database. (You are backing up your database and
wp-content directory on a regular basis, right? Right?)
To keep your database slimmed down, run the following SQL query, either from the command line (advanced level) or from phpMyAdmin:
DELETE FROM wp_posts WHERE post_type = "revision";
If you are using a different database prefix than
wp_you’ll need to adjust the above command accordingly.
Also, if you are using backup scripts to backup your database on a regular basis, you can even add that line to the script.
Managing Post Revisions
Post revisions are a great feature of WordPress, but they come with a price: they bloat your database and can slow down your site’s speed. My choice is not use them, but if you’re going to use them, it’s best to find a strategy that balances their benefits with their costs. I’m going to offer a few strategies you may want to consider to make the most of this highly useful feature.
Option 1: Disable Them
If you just don’t need them, why bother with them? Turn them off, delete any existing ones from your database and be done with it.
Option 2: Leave Them Be
If you find them useful and you seldom add new posts or edit old posts, why worry? The few that exist in your database probably aren’t adding that much weight and aren’t something you should lose sleep over. If it ain’t broke, don’t fix it.
Option 3: Limit Them
If you think you might find them useful in the near future, because you tend to edit drafts a lot and sometimes delete something you need (it’s not unusual for me to have twenty or more drafts at a time), but not long term because once a post is published it’s done you never touch it again, it may be best to just limit them to five or ten or whatever works for you, and call it a day. Keep it simple, silly.
Option 4: Periodically Purge
If you tend to have creative bursts where you write posts and edit them heavily and then walk away from things for a while, this may be the best strategy for you. Just purge all the post revisions once you’re well into that long period of not writing for a while.
Option 5: Purge, Then Backup
You can also leave posts revisions in place, and then purge them before you back up your database. As I mentioned earlier, if you’re using a script to back up your website, you can add that
DELETE FROM command to your backup script. This strategy keeps your backups lightweight, and is a good option if you have creative bursts as mentioned in option 4.
Option 6: Backup, Then Purge
As opposed to the strategy above, this may be more useful for you if you publish posts on a regular basis. Your website will always be working with the latest revision, but if you absolutely need something from a previous revision, it’s there in one of those backups.
WordPress post revisions are a great feature if you need them, although they can lead to database bloat. Fortunately, this is a WordPress option that works well, is fairly easy to manage, and with the tools I’ve given you above, you can learn how to make the most of it.
A lot of websites show you how to turn post revisions on or off or how to limit them, but very few of them show you how to delete them from your database. And in my research, I couldn’t find any that suggested strategies to manage them. In this article, I’ve given you six strategies to consider. If you have another that you use, please mention it in a comment.
Thanks for reading. If you have any questions, please leave a comment down below.
Support This Site
I don’t run ads on this site, so if you found this post useful or enjoyable, please support this site by sharing this post on your favorite social media by using the buttons above. If you would like to contribute to the server costs, you can also contribute via PayPal at paypal.me/kjodle. I appreciate your support.