Do you want to register and include jQuery from the Google CDN? While there’s probably a plugin for this, we have created a quick code snippet that you can use to load jQuery from the Google CDN with wp_register_script
in WordPress.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
add_action( 'init', 'jquery_register' ); function jquery_register() { if ( !is_admin() ) { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', ( 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js' ), false, null, true ); wp_enqueue_script( 'jquery' ); } }
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: How to set up author tracking in WordPress and 15 best content marketing tools.
Nice one I will add this to my blog right away!
Cool glad to hear you like the snippet.
why do this? not to say it isn’t good I am just not experienced enough.
Well CDN is content distribution/delivery network, it can improve access to the data and bandwidth etc. However you could easily replace that to something local this page has more details on loading locally.
http://codex.wordpress.org/Function_Reference/wp_enqueue_script
Aren’t we up to version 1.6.2 with jQuery now?
Whoops thanks Gabe, my bad grabbed an old version, updated!