CodeNewbie Community

toyagov
toyagov

Posted on

How To Remove jQuery Migrate From WordPress

jQuery Migrate greatly simplifies the process of moving older jQuery code to a higher jQuery version by identifying deprecated features. It then restores deprecated features and behaviors so that older code will still run properly on the current jQuery version and later.
Most up-to-date frontend code and plugins don’t require jquery-migrate.min.js. In most cases, this simply adds unnecessary load to your site. You can see this running if you launch Chrome Devtools console.

How to remove jQuery migrate from WordPress?

Removing jQuery migrate from WordPress is quite easy. You just need to add the following lines of code to your theme’s functions.php file.

//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' );
Enter fullscreen mode Exit fullscreen mode

Remove jQuery Migrate using WP Rocket Plugin

WP Rocket plugin comes with inbuilt functionality to remove jQuery migrate with a single click.

To remove jQuery Migrate using WP Rocket, goto WP Rocket plugin’s setting >> File Optimization.

Image description

Under the JavaScript Files section, you can check the box for Remove jQuery Migrate.
That’s it.

Reference Blog
How To Remove jQuery Migrate From WordPress

Discussion (0)