Get in touch
Back to blog
August 31st, 2022

How to Disable jQuery Migrate in WordPress

by Luca Reale
cropped-luca.png

The jQuery Migrate script is a useful feature of WordPress that enables developers to upgrade from older versions of jQuery to new ones. In this blog post, we will learn how to disable jQuery Migrate in WordPress as well as explaining how it works and why you may want to get rid of it.

Let’s get started!

What is jQuery Migrate?

jQuery Migrate is a JavaScript library that serves as a backward compatibility fix, allowing you to preserve the compatibility of your jQuery code developed for versions older than 1.9.

Some of its capabilities include restoring APIs that have been removed. The development version of the Migrate script can even show you warnings for missing or deprecated APIs, making it easy for you to update jQuery.

How Does it Work?

jQuery Migrate identifies deprecated features and restores them, enabling older code to run on the current jQuery version without a hitch.

This allows developers to upgrade to newer versions of jQuery, knowing that older code will still work.

How to Check if You Have jQuery Migrate

Various WordPress versions include the jQuery Migrate plugin on the front-end of your site; you can easily check if WordPress has it by checking the web page’s source code. If it’s active, you’ll notice source code that looks like the following.

Source code to check for jquery migrate script in WordPress

Reasons to remove jQuery Migrate

So, what would make you want to remove the jQuery Migrate script? Some reasons include:

  • Most plugins and front-end code don’t require jquery-Migrate.min.js. So this means it’s unnecessary and may slow down your site
  • If your site is using plugins that run on older jQuery code, it may be prone to security attacks, so it is better to switch to alternative plugins that are kept updated

How to remove jQuery Migrate from WordPress

Using a Plugin

This is the easiest way to do it, if you don’t fancy editing any site files. You simply install the Remove jQuery Migrate plugin, and it automatically removes the Migrate script from your site’s front end.

  • Sign in to your WordPress site and head to the Dashboard
  • Click Plugins and expand it to view more options, then click Add New
  • In the search bar, type Remove jQuery Migrate. Click Install Now, and then Activate

The plugin will now remove the Migrate script.

How to manually remove jQuery Migrate using functions.php

The manual method may be a bit complicated for some users. If you’re not confident with editing site files, we recommend making a backup of your site before proceeding. To manually remove jQuery Migrate, you’ll need to add a few lines of code to your theme’s functions.php file.

How to access functions.php

You can easily and quickly access the functions.php file through the WordPress Admin interface. To access it, follow these steps:

  • Log in to your WordPress Admin interface
  • In the left sidebar, click Appearances, then click Theme Editor
  • In the right sidebar, under Theme Files, click Theme Functions (functions.php)
  • The functions.php code editor will open, enabling you to code directly to the interface. Remember to save it when finished.

Once you’ve located your functions.php file, add the following code.

editing functions.php to remove jquery migrate
//Remove jQuery Migrate
function remove_jquery_Migrate( $scripts ) {
   if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) {
        $script = $scripts->registered['jquery'];
   if ( $script->deps ) { 
// Check whether the script has any dependencies
        $script->deps = array_diff( $script->deps, array( 'jquery-Migrate' ) );
 }
 }
 }
add_action( 'wp_default_scripts', 'remove_jquery_Migrate' );

That’s it! The Migrate script is now removed.

Final Thoughts

In this blog, you’ve learnt how to remove the jQuery Migrate script in your WordPress installation. For beginners, we recommend removing it by using a plugin. This is the easiest method and it ensures you can’t run into errors if you miss something while editing the code in your theme’s functions.php file.

We hope this simple tutorial solves your jQuery Migrate issue. Keep reading our blog for more tutorials about WordPress.

Category:
cropped-luca.png
Luca Reale
Content writer

Our newsletter

Our links

Our Work

Our Content

Social

Copyright © 2024 Drewl (Luna Digital Ltd.). All rights reserved