-
-
Save quangbahoa/c26d1b97019c713f87388a89a452fe5c 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://cdn.jsdelivr.net/npm/jquery@$core_version/dist/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