Remove jquery-migrate.js in WordPress

WordPress loads jquery-migrate.js in order to support older jQuery functions that some themes and WordPress plugins still use. However, many sites do not need jQuery Migrate, at all.

The following code snippet will remove jquery-migrate.js from your site.

Don’t do this unless you are absolutely sure that you understand the implications.

If you’re using old plugins or an old theme that use old jQuery functions, then removing jQuery Migrate may break those plugins and themes. If you’re sure that your themes and plugins do not require any deprecated jQuery functions, then you can use the following snippet to dequeue jquery-migrate.js (“dequeue” means to stop it from loading on your site).

If you’re not sure whether your theme or plugins need jquery-migrate.js, then you can try this. Remove jquery-migrate.js temporarily, and go through your site and test all of your plugins’ features to see if everything still works. If anything on your site breaks, then simply remove this snippet and everything will return to normal. This snippet makes no permanent changes, nor does it alter anything in your WordPress database. If you’re using an updated theme and plugins, everything should work just fine without jQuery Migrate. Good luck.

jQuery Migrate is loaded as a bundle with ‘jquery-core’ in WordPress. So the following code snippet removes the bundle, thereby removing jquery-migrate.js, then re-loads ‘jquery-core’ by itself.

/**
* Dequeue jQuery Migrate script in WordPress.
*/
function isa_remove_jquery_migrate( &$scripts) {
	if(!is_admin()) {
		$scripts->remove( 'jquery');
		$scripts->add( 'jquery', false, array( 'jquery-core' ), '1.12.4' );
	}
}
add_filter( 'wp_default_scripts', 'isa_remove_jquery_migrate' );

See more: , , ,

We've 6 Responses

    • January 6th, 2017 at 2:58 pm

      You’re welcome. To remove jquery.js altogether, remove line 7 from the code above, which is this line:

      $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.12.4' );

      Hope that helps.

      Isabel

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]