Created
May 6, 2012 00:15
-
-
Save markoheijnen/2606505 to your computer and use it in GitHub Desktop.
Cool way to include jquery from google on WordPress
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 | |
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