Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Created November 26, 2011 17:54
Show Gist options
  • Save chrisguitarguy/1396038 to your computer and use it in GitHub Desktop.
Save chrisguitarguy/1396038 to your computer and use it in GitHub Desktop.
Maybe load jQuery from the google cdn
<?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