Use Google-Hosted jQuery in Your WordPress Theme

How many sites use popular JavaScript libraries like jQuery? A lot. That’s why Google hosts many of them on their speedy CDN, so browsers only have to download jQuery or Prototype once in a day, instead of once per site.

How can your WordPress-powered site benefit from this? Digging into WordPress has the answer:

if ( !is_admin() ){
   wp_register_script('jquery', (""), false, '1.3.2');

This little snippet goes in your functions.php, where it deregisters WordPress’s internal copy of jQuery and references Google’s. Unfortunately, it’s not set up for the handy no-conflict mode that lets you use Prototype scripts on the same blog.

  • Milan

    This is not a right way to use Google-hosted jQuery in WordPress. You should simply install plugin Use Google Libraries which would automatically load jQuery from Google in noConflict mode and also load other libraries that are available from Google like jQuery UI, Prototype and SWFObject, without WordPress’ version added at the end of URL..

    And you don’t have to edit any file to add any code!

    • Matt

      Ah, I forgot about noConflict mode. Thanks for the plugin link.

  • Quang

    Nice post. And use following code if you are working offline:

    window.jQuery || document.write(”)