Annoying "JQMIGRATE: Migrate is..." in console after update to WordPress 4.5

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, or 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...

EDIT

WordPress 5.5 removed jQuery Migrate script, as a preparation step for updating jQuery to the latest version in 5.6. So the notice should be gone.

https://make.wordpress.org/core/2020/06/29/updating-jquery-version-shipped-with-wordpress/

Topic notices jquery Wordpress

Category Web


Just modify your Inspector Console when needed

Instead of hardcoding anything in your website, most inspectors give you method to edit the console output locally.

For Chrome and Opera

Using inspector console you can right click on the JQMIGRATE ... Warning and click 'Hide messages from jquery-migrate.js'.

Console Filter

This will add '-url:<YOUR_WORDPRESS_URL>/wp-includes/js/jquery/jquery-migrate.js?ver=3.3.2' to the console filter. Effectively subtracting this url from the console output.

Note: if you copying the above to the filters change out <YOUR_WORDPRESS_URL> for your wp url

This console filter is persistently applied to new tabs and windows as well.

Safari

For Safari you can create an inspector Response Local Override pretty easily.

Right click on the jquery-migrate.js:line to the right of the console log outputs, then select 'Create Response Local Override'.

Which means you edit the file locally for dev purposes. So to remove these migrate notices add this to the top of the jquery-migrate.js file in your Response Local Override.

/**
 * Response Local Override
 */
jQuery.migrateMute = true;

Firefox

Local overrides not supported currently. https://support.mozilla.org/en-US/questions/1331771

Tab/Window Based Filter Console output

type -jquery-migrate.js into the 'Filter Output' bar and Jquery migrate notices will disappear even on reload of tab.

Caveat: this console filter will need to be applied each time you open a new firefox tab or window.

Hope this helps!


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, 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.


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 (which outputs <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/


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.)


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 );
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.