Last active
January 30, 2024 14:46
-
-
Save knolaust/d28c1a62017d8de9996b9d000b84a2e1 to your computer and use it in GitHub Desktop.
Disable jQuery Migrate in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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