Skip to content

Instantly share code, notes, and snippets.

@markoheijnen
Created May 6, 2012 00:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markoheijnen/2606505 to your computer and use it in GitHub Desktop.
Save markoheijnen/2606505 to your computer and use it in GitHub Desktop.
Cool way to include jquery from google on WordPress
<?php
class Load_External {
private $jquery_path;
private function load_external_jquery() {
global $wp_scripts;
$schema = is_ssl() ? 'https://' : 'http://';
$jquery_version = $wp_scripts->registered['jquery']->ver;
$this->jquery_url = $wp_scripts->registered['jquery']->src;
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', $schema . 'ajax.googleapis.com/ajax/libs/jquery/' . $jquery_version . '/jquery.min.js', array(), $jquery_version, true );
wp_enqueue_script( 'jquery' );
add_action( 'wp_footer', array( &$this, 'load_local_jquery' ), 20 );
}
function load_local_jquery() {
if ( wp_script_is( 'jquery', 'done' ) ) {
echo '<script>window.jQuery || document.write(\'<script src="' . site_url() . $this->jquery_path . '"><\/script>\')</script>';
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment