Snippet: Disable jQuery Migrate

Disabling jQuery Migrate in WordPress can be beneficial for a couple of reasons:

  1. Performance: jQuery Migrate is a library that helps maintain compatibility with older versions of jQuery. If your WordPress site is running on the latest versions of WordPress and its plugins and themes, you might not need jQuery Migrate. Disabling it can reduce unnecessary script loading, improving the performance of your site.
  2. Security: Older versions of jQuery and jQuery Migrate might have known vulnerabilities. By disabling jQuery Migrate, you’re ensuring that your site isn’t using outdated and potentially insecure code.

However, before disabling jQuery Migrate, it’s essential to thoroughly test your site to ensure that everything continues to function correctly. Some themes or plugins might rely on features that require jQuery Migrate. If you encounter issues after disabling it, you may need to update your theme or plugins to versions that are compatible with the latest version of jQuery used by WordPress.

Add the following PHP code to your custom code within the builder / code plugin.

add_filter( 'wp_default_scripts', 'remove_jquery_migrate' );
function remove_jquery_migrate( $scripts ) {
	if ( empty( $scripts->registered['jquery'] ) || is_admin() ) {
		return;
	}
	$deps = & $scripts->registered['jquery']->deps;
	$deps = array_diff( $deps, [ 'jquery-migrate' ] );
}