Per default, the way to disable autosaving and post revisions, is to modify wp-config.php. Is there a way, to do that from within a plugin or a themes functions.php?

  • Have you already checked when and where the constants get checked for the first time? Any research? Also, please mind your markup. Thanks. Btw, I fixed your title to fit your spare contents. – kaiser Feb 2 '16 at 15:01
  • Did any of the answers worked for you? If so, it would be nice to accept since doing so builds trust to others facing the same issues. – marikamitsos Sep 11 '16 at 11:51
  • @marikamitsos I have posted it as answer. However, finally I've managed not to disable what WP thinks is reccomended. – T.Todua Sep 12 '16 at 14:02
  • In that case, you can always accept your own answer. Or even post how you've "...managed not to disable what WP thinks is recommended" – marikamitsos Sep 14 '16 at 14:12

You mentioned:

Is there a way, to do that from within a plugin or a themes functions.php?

You may want to try the following code. Just place it inside your theme's functions.php file. Using it, you do NOT have to alter the wp-config.php file.

define('WP_POST_REVISIONS', false);
function disable_autosave() {
add_action('wp_print_scripts', 'disable_autosave');

i have found this code:

define('my_revisions_amount', 1);         // let keep only one revision
define('my_autosave_interval', 600);      // 600 minutes is enough

if (IS_ADMINN){   
    add_filter( 'wp_revisions_to_keep', function(){
        return my_revisions_amount;
    } );
    add_filter( 'wp_print_scripts', function(){
        wp_localize_script( 'autosave', 'autosaveL10n', 
                   'autosaveInterval'=> my_autosave_interval,
                   'blog_id'         => get_current_blog_id(),
    }, 11 );    

This is my way of disabling autosave. It can be improved:

jQuery(document).ajaxSend(function( event, jqxhr, settings) {
    if(settings && settings.data && settings.data.indexOf("wp_autosave") > 0) {

Just checks the ajax request before it's sent to the server, and then cancels it if it's data contains wp_autosave string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.