Cain Manor

Your Guide To All Things Cain™

Using jQuery from Google

One of the largest items to load for a word­press blog is jQuery. Google cur­rently host most jQuery libraries on their site for pub­lic con­sump­tion. This appealed to me because Google is very, very fast, whereas my site is pretty fast, but not Google fast.

I tried var­i­ous plu­g­ins to do this, but none of them worked. I found this site, which shows how to make the change by hand.

This is my orig­i­nal 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 “reg­is­ter side­bar” and before “add fil­ter.” You can use what­ever ver­sion is avail­able on the site. I used 1.3.2 because it was the one spec­i­fied 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');
}

Comments are closed.