How to Remove jQuery and jQuery Migrate in WordPress?

remove jquery migrate

jQuery Migrate greatly simplifies the process of moving older jQuery code to 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.

Other reasons to remove jQuery and jQuery Migrate:

  • It’s better to keep your code, themes, and plugins updated than it is to patch in support of an extra file. Keeping your site updated also prevents it from Security attacks.
  • If you are running plugins that use older jQuery code, it’s probably better to update them or switch to an alternative kept updated.

How to remove jQuery and jQuery migrate from WordPress?

Removing jQuery and jQuery migrate from WordPress is quite easy. You just need to add following lines of code to your theme’s function.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' ) );
		}
	 }
 }

// Remove jQuery from your theme, but keep it in wp-admin
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
	wp_deregister_script('jquery');
}
 
add_action( 'wp_default_scripts', 'remove_jquery_migrate' );

Conclusion:

As I mentioned above, jQuery migrate adds unnecessary load to your site. Thus, I recommend removing it from your website or blog.

0938.54.84.99