Skip to content

Instantly share code, notes, and snippets.

@knolaust
Last active January 30, 2024 14:46
Show Gist options
  • Save knolaust/d28c1a62017d8de9996b9d000b84a2e1 to your computer and use it in GitHub Desktop.
Save knolaust/d28c1a62017d8de9996b9d000b84a2e1 to your computer and use it in GitHub Desktop.
Disable jQuery Migrate in WordPress
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment