Home / functions.php / Load jQuery from the Google CDN with wp_register_script
  • How to Load jQuery from the Google CDN with wp_register_script


    There are many reasons to use Google CDN when adding jQuery to the front end of your WordPress site. One of the these reasons is that many of your visitors may not need to download it at all. When your visitors browser sees a Google CDN hosted copy of jQuery and if available will load from their browser cache negating the need to download the file again. Adding this snippet to the functions.php of your wordpress theme will register and include jquery from the Google CDN.

    You may want to take a look at Googles hosted libraries to see what else is available.

    ( click code to copy )

    wordpress snippet : PHP

    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' );

    ( WordPress codex functions, hooks, in this snippet. )

    register, query, init, add_action, _e, is_admin, wp_deregister_script, wp_enqueue_script, wp_register_script, wp,
  • Gabe

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

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

  • paul

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

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