I was recently messing around with my website’s MySQL database, and I did something new and good. I searched around the internet and there is no script on the internet to delete WordPress post revisions using
functions.php file, so I created one. Believe me, it’s easy as making milkshake.
If we leave this code snippet in our
functions.php file, it will run indefinitely. That’s why I now recommend you to use the Code Snippets plugin and only run it once.
I highly recommend you install a separate plugin for code snippets. However, if you prefer not to, then you can add the following code to your theme’s
functions.php file and it’ll delete all the post revisions:
global $wpdb; $wpdb->query( " DELETE FROM $wpdb->posts WHERE post_type = 'revision' " );Code language: PHP (php)
Note: Remember to remove this code immediately after saving your
functions.php file. You only need to run this code once, there’s no need to keep this code in your theme.
That’s it! You have successfully removed all WordPress post revisions automatically.