Can anyone explain why is there a constant notice

JQMIGRATE: Migrate is installed, version 1.4.0

that points to load-scripts.php in my console when I updated my theme to WordPress 4.5, and how can it be removed?

It's not an error, but it's always present in my console, and I really don't see what's the point of it? Should I update something, make some changes to my code?

Maybe I have a bit of ocd, but usually when I inspect the site, I like to see errors and real notices that point to an issue in my console...

  • +1 to your very useful OCD. This probably come from the jquery migration/backward compatibility script. Any chance you use unminified/dev version of it? – Mark Kaplun Apr 24 '16 at 10:12
  • Unminified version of migrate? Not to my knowledge no, it could be some plugins, but upon inspection I don't see any of it :\ – dingo_d Apr 24 '16 at 11:40
  • 1
    note both versions are in WP dirs: /wp-admin/js/jquery/jquery-migrate.js and /wp-admin/js/jquery/jquery-migrate.min.js – majick Apr 25 '16 at 9:40
up vote 41 down vote accepted

WordPress uses the jQuery migrate script to ensure backwards compatibility for any plugins or themes you might be using which use functionality removed from newer versions of jQuery.

With the release of WordPress 4.5, it appears they have upgraded the version of jQuery migrate from v1.2.1 to v1.4.0 - Having a quick scan through the code reveals that v1.4.0 logs that the script is loaded regardless of whether or not the migrateMute option is set and in both the uncompressed and minified versions.

The only way to remove the notice is to ensure all your plugins/theme code don't rely on any old jQuery functionality, and then remove the migrate script. There's a plugin out there to do this, but it's quite a simple method that can just be placed in your theme's functions file or similar:

add_action('wp_default_scripts', function ($scripts) {
    if (!empty($scripts->registered['jquery'])) {
        $scripts->registered['jquery']->deps = array_diff($scripts->registered['jquery']->deps, ['jquery-migrate']);
    }
});

Please note that this is not considered best practice for WordPress development and in my opinion the migrate script should not be removed just for the sake of keeping the developer console clean.

  • So basically one of my plugins is depending on a functionality that was a part of the old jQuery version? Is there a way to find out what that functionality is? Or am I safe to just mute the migrate script? – dingo_d Apr 24 '16 at 12:24
  • 1
    I can't say for sure whether any of your plugins depend on old functionality, WordPress just includes the migrate script as a safe default in case your install has any plugins which haven't been updated in a while. If it were me I'd remove the migrate script on a local install of the site and then check everything still works as expected, ensuring there are no errors in the console etc. – Andy Apr 24 '16 at 12:29
  • I recommend against this. This backwards compatibility is there for a reason. It is the jQuery equivalent of deleting deprecated functions file in WordPress. Going to all the trouble of verifying whether your current setup is fully compatible does not even account for changes of setup or plugin additions, and given the potential problems you'd be creating does not balance against the completely dubious benefit of removing a console log message. – majick Apr 25 '16 at 7:54
  • 1
    @majick It's beyond the scope of this answer to discuss whether removing the script is a good idea or not, this specifically addresses the issue of how to remove the message in the console. FWIW, I think removing the script is a bad idea also. I think the downvote is uncalled for, as my answer perfectly answers the OPs question. – Andy Apr 25 '16 at 8:49
  • 1
    sorry I don't downvote often, but felt it was needed here as there is no warning that this may not be a good idea and is the opposite of best practice in development (add a warning and i'll remove the downvote.) I believe the question is asking how to remove just the console message not how to remove jquery migrate itself. if someone asked how to remove the update nag message in WordPress you wouldn't answer "just uninstall WordPress." – majick Apr 25 '16 at 9:10

You could change the log message text to blank in jquery-migrate.min.js but this will not be preserved on core update.

The alternative is to add passthrough/filter function copy of console.log to just before the migrate script is loaded, and tell it to ignore logging messages that contain 'Migrate is installed'. Doing it this way will preserve other Migrate warnings too:

// silencer script
function jquery_migrate_silencer() {
    // create function copy
    $silencer = '<script>window.console.logger = window.console.log; ';
    // modify original function to filter and use function copy
    $silencer .= 'window.console.log = function(tolog) {';
    // bug out if empty to prevent error
    $silencer .= 'if (tolog == null) {return;} ';
    // filter messages containing string
    $silencer .= 'if (tolog.indexOf("Migrate is installed") == -1) {';
    $silencer .= 'console.logger(tolog);} ';
    $silencer .= '}</script>';
    return $silencer;
}

// for the frontend, use script_loader_tag filter
add_filter('script_loader_tag','jquery_migrate_load_silencer', 10, 2);
function jquery_migrate_load_silencer($tag, $handle) {
    if ($handle == 'jquery-migrate') {
        $silencer = jquery_migrate_silencer();
        // prepend to jquery migrate loading
        $tag = $silencer.$tag;
    }
    return $tag;
}

// for the admin, hook to admin_print_scripts
add_action('admin_print_scripts','jquery_migrate_echo_silencer');
function jquery_migrate_echo_silencer() {echo jquery_migrate_silencer();}

The result is a one line of HTML script added to both frontend and backend that achieves the desired effect (prevents the installed message.)

  • 1
    +1 for the idea, but if it is your site, it is probably better to just make sure all your scripts are compatible to the latest version and remove the migrator ;) – Mark Kaplun Apr 25 '16 at 9:11
  • yes but I just don't agree with removing the migrator as a practice at all because it doesn't take into account installing themes/plugins which may not be compatible with the latest jQuery yet. as a parrallel there are plenty of plugins that still work fine even though they may not have realized a WordPress function here or there is "officially" deprecated. backwards compatibility is prevention and better than a cure when it comes to both cases and well, software in general. – majick Apr 25 '16 at 9:18
  • 2
    You are right, but not supporting the latest jquery version is a bug IMO. 4.5 went into RC about a month ago, and if code wasn't tested to work with all the changes it introduced, then the theme/plugin are not truly compatible. In the world outside wordpress deprecation messages turn into actual deprecation at some point, and you don't want to leave handling them to the time where you have to upgrade ASAP. The migrator IMO should be a temporary solution, not a permanent feature. – Mark Kaplun Apr 25 '16 at 9:29
  • 2
    I disagree on principals here, the internet is a fast moving target and the landscape is changing all the time. (by the time it took to get the site logo feature to 4.5 for example, sites had move on from the idea of having only one logo). Old is good only when applied to very specific and stable niches but jQuery for example is know to be a relatively moving target. – Mark Kaplun Apr 25 '16 at 9:46
  • 1
    A theme is not an isolated product. If a theme was packaging wordpress and jquery etc, then the age of the theme would have been totally relevant. As no theme does that, if the theme was not tested against the version of wordpress being used, then it is not clear enough what kind of bugs will be discovered. This is just another manifestation of the static vs dynamic linking dilemma. In a static linking world your claim is mostly true, but wordpress is dynamic linking and just because something had worked with 3.5 do not mean it will work with 4.5 even with the attempt to be backcompatible – Mark Kaplun Apr 25 '16 at 10:54

Just a little test here.

I peeked into jquery-migrate.js and noticed this part:

// Set to true to prevent console output; migrateWarnings still maintained
// jQuery.migrateMute = false;

so I tested the following with the newly wp_add_inline_script(), introduced in version 4.5:

add_action( 'wp_enqueue_scripts', function()
{   
    wp_add_inline_script( 
        'jquery-migrate', 'jQuery.migrateMute = true;',
        'before' 
    );
} );

This will change:

JQMIGRATE: Migrate is installed with logging active, version 1.4.0

to:

JQMIGRATE: Migrate is installed, version 1.4.0

So it doesn't actually prevent all console output, like this part in jquery-migrate.js:

// Show a message on the console so devs know we're active
if ( window.console && window.console.log ) {
    window.console.log( "JQMIGRATE: Migrate is installed" +
        ( jQuery.migrateMute ? "" : " with logging active" ) +
        ", version " + jQuery.migrateVersion );
}
  • 1
    So the bottom code just removes the message, right? I mean, the migrate stays but the message is supressed, right? This is better than removing the migrate definitely – dingo_d Apr 25 '16 at 9:47
  • 1
    no, that is a copy of the code producing the console log message that does output. it shows that migrateMute is only tested for the second half of the console message - the first half is output regardless... removing this code block will remove the console message, but you would need to redo that each WP update. – majick Apr 25 '16 at 9:56
  • 2
    Thanks for the research and details! IMO the best option, since removing JQmigrate is not always a good idea, because many WP plugins depend on deprecated jQuery functions. This solution helps to clean up the console output a bit! – Philipp Apr 28 '17 at 17:39

Had the same problem, and found out you just need to set 'SCRIPT_DEBUG' to 'false' in your wp-config.php. Hope this helps someone

Solution:

add this to functions.php:

function remove_jquery_migrate_notice() {
    $m= $GLOBALS['wp_scripts']->registered['jquery-migrate'];
    $m->extra['before'][]='temp_jm_logconsole = window.console.log; window.console.log=null;';
    $m->extra['after'][]='window.console.log=temp_jm_logconsole;';
}
add_action( 'init', 'remove_jquery_migrate_notice', 5 );

It works when jquery-migrate is called with standard hook <link rel=stylesheet....> and not with load-scripts.php in bulk (like in admin-dashboard).

As mentionned previously by Andy WordPress uses the jQuery migrate script to ensure backwards compatibility and this is why it is automatically loaded by default.

Here's a safe way to remove the JQuery Migrate module and thus get rid of the annoying JQMIGRATE notice while speeding up the loading of your page on the client side. Simply copy/paste this code in your functions.php file and you're done:

<?php
/**
 * Disable jQuery Migrate in WordPress.
 *
 * @author Guy Dumais.
 * @link https://en.guydumais.digital/disable-jquery-migrate-in-wordpress/
 */
add_filter( 'wp_default_scripts', $af = static function( &$scripts) {
    if(!is_admin()) {
        $scripts->remove( 'jquery');
        $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.12.4' );
    }    
}, PHP_INT_MAX );
unset( $af );


More details

To get more details about the reason I'm using a static function, read my article here:
►► https://en.guydumais.digital/disable-jquery-migrate-in-wordpress/

  • downvoted because 1. this smells too much of a spam and just does the minimal effort to feel like an answer. 2. You hard code the version nullifying cache busting. – Mark Kaplun Apr 26 at 16:42
  • its a shame because its a nice approach, even tho you're using add_filter when its actually an action. – pcarvalho yesterday

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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