Last active
December 4, 2020 13:48
-
-
Save omniacode/b9f1e459e526c16bf8a955921fbd0eba to your computer and use it in GitHub Desktop.
Use Repository Hosted jQuery for Wordpress
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
<?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