Created
February 6, 2014 10:03
-
-
Save ingozoell/8841462 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** * Load jQuery from Google CDN, fallback to local */// http://wp.tutsplus.com/tutorials/load-jquery-from-google-cdn-with-local-fallback-for-wordpress/if( !is_admin()){ // Don't do this for admin area, since Google's jQuery isn't in noConflict mode and will interfere with WP's admin area. $url = 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/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.6.2/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_deregister_script('jquery'); // deregisters the default WordPress jQuery wp_register_script('jquery', get_bloginfo('template_url').'/js/jquery-1.6.2.min.js', __FILE__, false, '1.6.2', true); // register the local file wp_enqueue_script('jquery'); // enqueue the local file } 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