• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Limit the number of WordPress revisions by code

Discover in this tutorial how to limit the number of entries and page revisions that WordPress saves using a code snippet.

WordPress has an autosaving system that is great for avoiding scares. However, each revision takes up the same space as the article.

Therefore, if you have 20 revisions of each post you are increasing the size of the WordPress database considerably, which slows down the loading speed of the web.

Although there are plugins like WP-Optimize that are very practical for keeping the database optimized, in this case you only need to limit the number of revisions to make sure it doesn’t grow too much.

In addition, this preventive measure can be applied with a simple line of code:

Snippet to limit WordPress revisions

Add the following fragment somewhere before the line containing “require_once(ABSPATH….” in the wp-config .php file:

To see this and another 847 code snippets of this website, login or subscribe here.

It’s as simple as that.

With this block only the last 5 versions of the entries and pages will be saved.

Are you interested in keeping a copy of a larger or smaller number of revisions? Change the snippet for a more convenient one.

Conclusion

As you can see, with one line of code you can limit the number of revisions of entries and pages that WordPress saves automatically.

It’s a simple and practical trick to keep the size of the database at bay and make sure it’s optimized.

I use it often. I hope you find it useful too.

Any questions? I read you in the comments.

And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉

PHP WordPress wp-config

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2023

Lost your password?