How to disable and delete WordPress post, page revisions? Change Autosave and Trash delete setting

App Shah

Crunchify » Blogging Tips » How to disable and delete WordPress post, page revisions? Change Autosave and Trash delete setting

WordPress Post Revisions - Crunchify Tips on how to delete it?

What is WordPress Revision?

In WordPress revisions are records of each stored draft and published post data. Every time, when you save your draft either by autosave or manual, WordPress stores complete snapshot of your post or page data in Database.

This is very useful in case you have unexpected system failure, power outage or more and want to retrieve your work later. It will be retrieved from Database later on.

WordPress Revisions - Crunchify Tips - Fine-tune settings

WordPress revision was introduced in WordPress 3.6 and it was a great addition. Even though WordPress revisions are very useful, having it auto enabled without any fine tuning may store thousands of revisions in Database and may slow down your Database performance and eventually your Site/Blog.

We do have Crunchify Premium site and I would like to keep all revisions for tracking purpose but on main blog site, I think having so many revisions are not that helpful. In later case, having revision of posts are simply not usable.

Is it wise to delete post revisions and autosaves from database?

I would say it depends on your use. At least try to optimize (fine tune) or completely disable it.

How to disable autosave using wp-config.php change?

Open your site’s wp-config.php file and add below line at the very bottom of the file.

  • Change WordPress post revisions to 3 only.
  • Change Autosave interval to 2 minutes.
define( 'WP_POST_REVISIONS', 3); // only allow 3 post revisions
define( 'AUTOSAVE_INTERVAL', 120 );  // set default save interval to 2 mins

How to Disable WordPress Post Revisions using functions.php change?

Just add below code to your theme’s functions.php file. This will disable revisions completely for post and pages.

add_action('admin_init', 'crunchify_disable_revisions');
function crunchify_disable_revisions(){
    remove_post_type_support('post', 'revisions');
    remove_post_type_support('page', 'revisions');

How to Delete WordPress Post Revisions?

There are multiple ways to delete Post and Page revisions from your WordPress Database tables.

One option is to use Plugin which deletes revisions but I would just do the same task with simple code below.

This query will delete all revisions from your Database table. Please don’t execute query in MySQL editor as it may not delete related term metadata. This codebase will make sure that you have your DB cleanup right way. 🙂

function crunchify_delete_all_revisions () {

    global $wpdb;
    // This query will delete all revisions from your Database table.
    $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT `ID` FROM $wpdb->posts WHERE `post_type` = 'revision'") );

    foreach ( $revision_ids as $revision_id ) {
        wp_delete_post_revision( $revision_id );
add_action( 'admin_init', 'crunchify_delete_all_revisions' );

Will removing revisions positively impact database performance?

I believe yes. At Crunchify, our goal is to improve page speed load and we have this same setting on our blog.

If you also wish to disable autosave for specific post types, you can do this:

In this case, autosave will be disable only for post type and not page type.

add_action('admin_print_scripts', 'crunchify_disable_autosave');
function crunchify_disable_autosave(){
    global $post;
    if(get_post_type($post->ID) === 'post'){

There are few more optimization you could do.

  • Empty trash automatically after 1 day. Add below code to wp-config.php file.
define( 'EMPTY_TRASH_DAYS',  1 ); // Empty trash after 1 day

I hope this will help you optimize and customize your WordPress site further. Let me know if you face any issue running this code.

Leave a Comment