Last active
April 6, 2023 10:52
-
-
Save Shelob9/de011337264ed365c52dc1561746ec12 to your computer and use it in GitHub Desktop.
Replace WordPress' jQuery with CDN jQuery of the right version
This file contains 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
add_action( 'init', function(){ | |
if ( ! is_admin()) { | |
if( is_ssl() ){ | |
$protocol = 'https'; | |
}else { | |
$protocol = 'http'; | |
} | |
/** @var WP_Scripts $wp_scripts */ | |
global $wp_scripts; | |
/** @var _WP_Dependency $core */ | |
$core = $wp_scripts->registered[ 'jquery-core' ]; | |
$core_version = $core->ver; | |
$core->src = "$protocol://ajax.googleapis.com/ajax/libs/jquery/$core_version/jquery.min.js"; | |
if ( WP_DEBUG ) { | |
/** @var _WP_Dependency $migrate */ | |
$migrate = $wp_scripts->registered[ 'jquery-migrate' ]; | |
$migrate_version = $migrate->ver; | |
$migrate->src = "$protocol://cdn.jsdelivr.net/jquery.migrate/$migrate_version/jquery-migrate.min.js"; | |
}else{ | |
/** @var _WP_Dependency $jquery */ | |
$jquery = $wp_scripts->registered[ 'jquery' ]; | |
$jquery->deps = [ 'jquery-core' ]; | |
} | |
} | |
},11 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment