Load jQuery From the Google CDN with wp_register_script

Snippets by IsItWP

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.


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.

Comments   Leave a Reply

  1. Nice one I will add this to my blog right away! 

    1. Cool glad to hear you like the snippet.

  2. why do this? not to say it isn’t good I am just not experienced enough.

    1. 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.


  3. Aren’t we up to version 1.6.2 with jQuery now?

    1. Whoops thanks Gabe, my bad grabbed an old version, updated!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!