Created
November 26, 2011 17:54
-
-
Save chrisguitarguy/1396038 to your computer and use it in GitHub Desktop.
Maybe load jQuery from the google cdn
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 | |
/* | |
Plugin Name: Google jQuery CDN | |
*/ | |
add_action( 'wp_enqueue_scripts', 'cd_wp_google_jquery' ); | |
function cd_wp_google_jquery() | |
{ | |
if( $works = get_transient( 'google_jquery_works' ) ) | |
{ | |
wp_deregister_script( 'jquery' ); | |
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'); | |
} | |
else | |
{ | |
$url = 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'; | |
$resp = wp_remote_get( $url ); | |
if( ! is_wp_error( $resp ) && 200 == $resp['response']['code'] ) | |
{ | |
set_transient( 'google_jquery_works', true, 60*60 ); | |
wp_deregister_script( 'jquery' ); | |
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js' ); | |
} | |
} | |
wp_enqueue_script('jquery'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment