Disable jQuery Migrate in WordPress

01/30/2024
Back to Blogs
<?php
/**
 * Remove jQuery Migrate dependency from jQuery in the frontend.
 *
 * This function removes the jQuery Migrate script dependency from the jQuery script
 * when loading scripts in the frontend to improve performance.
 *
 * Gist Keywords: wordpress, jquery, javascript, performance
 *
 * @category WordPress
 * @author   Knol Aust
 */

add_action( 'wp_default_scripts', function ( $scripts ) {
	if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) {
		$script = $scripts->registered['jquery'];
		if ( ! empty( $script->deps ) ) {
			$script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) );
		}
	}
}, 150 );