How to limit post revisions in WordPress


In this tutorial, you will learn how to limit post revisions in WordPress. WordPress post revision can be helpful for blogger or website owner to compare the previous changes of posts with the newer one. As we know that WordPress is the most popular CMS that used worldwide to manage the website. It generates the runtime HTML code to display the contents on the browser.

By limiting the post revisions, it will improve the:

  • Website performance
  • Reduce database size
  • Faster rendering of HTML code

Note: Before making any changes to your website, keep the latest backup of database and website.

Limit WordPress Revisions

By default WordPress stores every revision of posts into the database. You can limit it by adding the following code to your wp-config.php file.

By adding the below code, WordPress will store all the revisions of posts.

wp-config.php
define( 'WP_POST_REVISIONS', true);

To limit the post revisions, you need to the add:

wp-config.php
define( 'WP_POST_REVISIONS', 4);

Now WordPress will store only 4 revisions of the post into the database. And to disable the post revisions, your code will be:

wp-config.php
define( 'WP_POST_REVISIONS', false);

true (default), -1: store every revision.

false, 0: do not store any revisions (except the one autosave per post).

(int) > 0: store that many revisions (+1 autosave) per post. Old revisions are automatically deleted.

To delete the revisions form the database, you can use the following query:

DELETE FROM wp_posts WHERE post_type = "revision";</code

Hope it will help to make your website faster. Thank You 🙂

References

  1. WordPress Revisions

Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.