Using jQuery from Google

One of the largest items to load for a wordpress blog is jQuery. Google currently host most jQuery libraries on their site for public consumption. This appealed to me because Google is very, very fast, whereas my site is pretty fast, but not Google fast.

I tried various plugins to do this, but none of them worked. I found this site, which shows how to make the change by hand.

This is my original function.php from my theme

<?php
if ( function_exists('register_sidebar') )
    register_sidebar();
 
add_filter('comments_template', 'legacy_comments');
function legacy_comments($file) {
	if(!function_exists('wp_list_comments')) 	$file = TEMPLATEPATH . '/legacy.comments.php';
	return $file;
}
 
?>

To get it to work, you need to insert this code after “register sidebar” and before “add filter.” You can use whatever version is available on the site. I used 1.3.2 because it was the one specified in my theme and it was smaller than the 1.4 versions.

if(is_admin()) return;
 
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js');
wp_enqueue_script('jquery');
}