Skip to content

Instantly share code, notes, and snippets.

@squaremunkey
Forked from isGabe/gist:3072378
Last active August 29, 2015 14:07
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 squaremunkey/eee903ea12f0103020ef to your computer and use it in GitHub Desktop.
Save squaremunkey/eee903ea12f0103020ef to your computer and use it in GitHub Desktop.
<?php
/*
**** Load jQuery from Google CDN if available, local fallback if not ****
** Place in your theme's functions.php or relevant file. Edit local jQuery path if needed.
** Works as-is with WordPress Bones Theme v1.2 https://github.com/eddiemachado/bones (replace wp_enqueue_script( 'jquery' ); on line 142
** reference: http://wp.tutsplus.com/tutorials/load-jquery-from-google-cdn-with-local-fallback-for-wordpress/
*/
$url = 'http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js'; // the URL to check against
$test_url = @fopen($url,'r'); // test parameters
if($test_url !== false) { // test if the URL exists
function load_external_jQuery() { // load external file
wp_deregister_script( 'jquery' ); // deregisters the default WordPress jQuery
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js'); // register the external file
wp_enqueue_script('jquery'); // enqueue the external file
}
add_action('wp_enqueue_scripts', 'load_external_jQuery'); // initiate the function
} else {
function load_local_jQuery() {
wp_enqueue_script('jquery'); // enqueue built in WordPress version
}
add_action('wp_enqueue_scripts', 'load_local_jQuery'); // initiate the function
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment