If you revise your posts a lot in WordPress, you probably are racking up quite a bit of post revisions stored in your database. With time, and as your site grows, this could weigh your database down.
In fact, you really don’t need 10 post revision, and not even 5. Usually 2 or 3 post revisions are good.
So, how do you limit post revisions in WordPress?
How to Limit Post Revisions In WordPress
Method on how to limit post revisions in WordPress for the code savvy
If you are familiar with, or not scare of editing your wp-config.php file, you can put before the code for your wp-settings.php reference toward the bottom of the file the following code snippet.
/** Define number of Post Revisions allowed in MySQL. */ define ('WP_POST_REVISIONS', 2);
For this short tutorial, I have limited the revisions to 2, but you can just change the number to what you desire.
I have seen a lot of tutorials that just have one line, but for documentation purposes, I added the line before it. This is great for those who have multiple developers who work on their website, or if you originally developed the site and left it into the site owner’s hands to figure out. It’s just common courtesy.
You can also disable post revisions:
/** Define number of Post Revisions allowed in MySQL. */ define('WP_POST_REVISIONS', false );
As you can see, the different between the previous code snippet and this one is that you have defined it as false instead of a number.
Method on how to limit post revisions in WordPress for the not so code savvy
If you really donn’t want to deal with code and just want to install a plugin, Revision Control should be a good addition to your website.
I do want to note that some people have said that when upgrading WordPress and using Revision Control, you will need to reset your plugin’s limit after the upgrade so it will work properly again.
Please do note that these methods will not remove whatever post revisions you currently have. You will have to put in another method.
Have you ever had any problem with your database getting bloated with post revisions? What method do you using to limit post revisions in wordpress?
Kesha Brown says
Haven’t had a problem to date but will def start adding a number to the config file as a best practice….thanks so much for the prompt!
And yes, adding comments is always a best practice! I can’t tell you how many times it’s helped me find code a whole lot faster! 🙂
Nile says
I am glad you have not had a problem. I have a post to clean up extra post revisions and some of it I have to actually explain why the one code we have always known is probably not the best method, while also providing the alternative method.
I have been lax in the past about not documenting my code and after some time it just clicked that it would be a nice thing to do for other developers.
Anonymous says
I have lost extra revisions so i need implement it actually. Thanks for sharing
Robert Koening says
Plug-ins seem to be the best option for people dealing with issues on WordPress. I think that I will utilize the plug-in so that I can avoid multiple revisions. Less headaches! Thanks!
Yorinda says
Hi Niles,
thank you for the great tutorial and the extra tips.
Just to clarify, the revisions are each changed version of the post we write?
So, by setting it to only keep two, does that mean it will keep the last two?
Technology is so amazing, just a few letters of code and it is all programmed!
Much appreciated!
Yorinda
Jason says
I didn’t even realize that this was even a problem. I am not even sure if it is even something I need to even be worrying about. If I mess it it, will I break my site?
alex says
i have tryed all types of plugins for my site,none seem to work or any widgets,maybe i dont have flash or java or this,i am new so dont know a lot about websites and how they work really.
Thomas says
Hi Nile
I am using a plugin called Revision Diet. It is very simple to use, but maybe I should use your code tip instead and then remove the plugin. I think I will start making a backup just in case I make some mistakes 🙂
Nile says
Just to let you know, Revision Diet hasn’t been updated in over 2 years.
Thomas says
That is a good point. I have tried to disable the plugin and insert the code in my wp-config.php file, but it does not work for some reason. It keeps on saving extra revision even that I have set the numbers to only 3. Do you have any ideas on how to troubleshoot this issue?
Nile says
You will have to completely delete the plugin, but you will probably have to go and edit your database and find the table in wp_options that is controlled by the Revision Diet plugin.
Sarupa Shah says
Hi Niles – my question is the same as Yorinda’s – does it only keep the lat 2 revisions or limit you to 2 revisions only if you follow your tips 😉
Nile says
It keeps the 2 latest revisions, and discards older ones in exchange for the newer ones so you will always just keep 2 revisions.
Okto says
Hi Nile,
Honestly, I never aware on risk of weigh my database. And you get me again. I’m not a tech savvy blogger :(, then the plugin link you have provided help me a lot. Going to check for it
Thanks for the post
Debopam Banerjee says
Thanks for the share… I personally have not felt any problem till now…. Thanks for letting me know about the problem and be aware of the problem……
Krishna says
well If we do not use the mod which you have mentioned above how many times does our WordPress blog save our post every time we revise or update? If we update a post 10 times will it create 10 copies? If at all we want to use a plugin to set post revisions what is the best available plugin for this purpose? ‘Better Delete Revision’ is used to completely remove revisions right.
After reading this post I went to my WordPress dashboard and I opened a already published post but I could find how to revert back to previous edits. can you tell me how to do it in detail.
thanks!!
Rohit says
I don’t know if there is any need of limiting post revisions at all, these revisions are like checkpoints and sometimes they are very much needed to restore a particular state of the article..,
by the way its always been nice to know a trick, and i love that. thanks for same..:)
Nile says
Hi Rohit! Your site must not be very big yet or have a lot of traffic. Post revisions are often stored and depending on the length of post, 5 to 10 revisions can become quite a bit of a drag on your hosting account’s database… especially if you have quite a few articles. That is where you will want to seriously consider limiting your post revisions.
Danish Ali says
I have lost extra revisions so i need implement it actually. Thanks for sharing
Plaban says
I don’t really want to mess with any codes so I use the Revision Control plugin. It works well and keeps my blog’s database small and compact.
Hamza Sheikh says
I have used revisions feature in the past to recover, and analysis on my posts. However, this is a great tutorial on how to limit post revisions because somehow they generate lot of mess in the database. I have used several plugins to delete revisions after my initial testing.
David Merrill 101 says
I was not aware that post revisions caused this sort of overload, Nile.
These are good suggestions to minimize the problem.
I’m not much of a tech guy, so would probably opt for the plugin. I always prefer the easy way out… lol.
Cherrie Bautista says
I prefer changing the code if I have specific instructions, rather than activating another plugin, though I think my database backup and optimizer plugin is already deleting post revisions every week. This is good to know, though. Thank you Niles!
vishvast says
i have tryed all types of plugins for my site,none seem to work or any widgets,maybe i dont have flash or java or this,i am new so dont know a lot about websites and how they work really.
Phil McDonnell says
Great post! I have to 100% agree with you that these revisions bog down the database after a while. For my clients I have found a great plugin that not only deletes the revisions but empties the spam/trash and optimizes the database tables as well. It can be done manually or scheduled.
http://wordpress.org/plugins/rvg-optimize-database/
From the codex description:
This plugin is a ‘One Click’ WordPress Database Cleaner / Optimizer.
Main Features
Deletes redundant revisions of posts and pages (you optionally can keep an ‘x’-amount of the most recent revisions)
Deletes trashed posts, pages and comments (optional)
Deletes spammed comments (optional)
Deletes ‘orphan postmeta items’
Optimizes the database tables (optionally you can exclude certain tables from optimization)
Creates a log file of the optimizations (optional)
Optimization can be scheduled to automatically run once hourly, twice daily, once daily or once weekly at a specific time (optional)
‘Optimize DB (1 click)’ link in the admin bar (optional)
Samantha Vermillion says
Hi,
I never knew this actually existed. Too many post revisions for every blog post would cause unnecessary increase in the database size.
Thanks.