Skip to content

Instantly share code, notes, and snippets.

@omniacode
Last active December 4, 2020 13:48
Show Gist options
  • Save omniacode/b9f1e459e526c16bf8a955921fbd0eba to your computer and use it in GitHub Desktop.
Save omniacode/b9f1e459e526c16bf8a955921fbd0eba to your computer and use it in GitHub Desktop.
Use Repository Hosted jQuery for Wordpress
<?php
// Load jQuery from Google Lib
if( !is_admin()){
$url = 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js';
$test_url = @fopen($url,'r');
if($test_url !== false) {
function load_external_jQuery() {
wp_deregister_script('jquery');
wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js', '', '', true );
wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'load_external_jQuery');
} else {
function load_local_jQuery() {
wp_deregister_script('jquery');
wp_register_script( 'jquery', includes_url( '/js/jquery/jquery.js' ), false, '', true );
wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'load_local_jQuery');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment