Not all WordPress need jQuery Migrate. So, if your site is quite modern and not using old plugin and themes. The chance is that you can remove jQuery Migrate. So, it will make your site faster and lighter

DifficultyEasy
ToolsBrowser’s Dev Tools
Requirement
  • Access to function.php
  • Access to wp_config.php

What is jQuery Migrate?

Put simply, jQuery Migrate is a library of JavaScript required to maintain backward compatibility. Older version of WordPress’s themes and plugins have different coding style, and WordPress is ethically obligated to keep the backward compatibility. It is the most popular CMS (Content Management System) and all.

So, that means, if you only use all new and updated plugins/themes for your WordPress site, it is pretty likely that you do not need this jQuery Migrate.

One less script to download will make your website fully loaded faster. Hence, increased PageSpeed/YSlow Index is just a pleasant side effect, as the real treasure is that your reader got served your content more quickly.

Check first whether jQuery Migrate is active or not

Remove jQuery Migrate from WordPress

Before we try to remove something, I think it is wise to make sure that ‘something’ is there, right? (Otherwise, no need to remove anything)

So, do it on your desktop, not mobile devices. Using your internet browser, activate the developer tools (Usually press F12 – just Chrome/Firefox -recommended), and browse around your WordPress site.

Pay attention to the ‘Console’ panel. If the jQuery Migrate is active, you will see a notification that looks like this:

    JQMIGRATE: Migrate is installed, version x.y.z

How to remove jQuery Migrate in WordPress

Although jQuery Migrate is loaded as a separate script, it is being summoned by the main jQuery script as one of its dependence. So, you will file no enqueued or registered script that needs to be dequeued or deregistered.

Instead, you need to put the following code in your child theme’s functions.php (you do use a child theme, don’t you?)

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

Verify That Nothing Is Broken

Before you can mark this task as done, you need to check if nothing is broken.

First, enable the script debugging via wp_config.php

define('SCRIPT_DEBUG', true);

Then fire up your browser and activate the Developer Tools (Usually by pressing F12). Make sure browse around your website to check if anything is out of place. Watch the ‘Console’ closely for any error.

If you have some problems inside the admin site only (/wp-admin/), try to exclude the admin site by changing the if statement in remove_jqm function above to:

if ( ! is_admin() && ! empty( $scripts->registered['jquery'] ) ) {

If the code broke your site, remark the code snippet in the modification of functions.php above. After re-upload it. reconfirm the abnormality has gone as well. (Otherwise, it is probably not caused by your attempt to remove jQuery Migrate)

Done

OK. All done to remove Remove jQuery Migrate. Let’s move to the next one!