Skip to content

Instantly share code, notes, and snippets.

@bouveng
Created May 22, 2020 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bouveng/419b3bf8fcebde2ddea06d6702260803 to your computer and use it in GitHub Desktop.
Save bouveng/419b3bf8fcebde2ddea06d6702260803 to your computer and use it in GitHub Desktop.
$jq_integrity = 'sha256-xNzN2a4ltkB44Mc/Jz3pT4iU1cmeR0FkXs4pru/JxaQ=';
$jq_crossorigin = 'anonymous';
$jq_cdn = 'https://code.jquery.com/jquery-3.5.0.min.js';
$jq_version = '3.5.0';
if(! is_admin()){
function add_cdn_attrs( $tag, $handle, $src ) {
global $jq_integrity, $jq_crossorigin;
if ( 'jquery' === $handle ) {
$tag = '<script src="' . esc_url( $src ) . '" integrity="' . $jq_integrity . '" crossorigin="' . $jq_crossorigin . '"></script>'."\n";
}
return $tag;
}
function replace_core_jquery() {
global $jq_cdn, $jq_version;
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', $jq_cdn, array(), $jq_version );
}
add_filter( 'script_loader_tag', 'add_cdn_attrs', 10, 3 );
add_action( 'wp_enqueue_scripts', 'replace_core_jquery' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment