Call Google’s jQuery Library in Your Template

Why use your own bandwidth when you can use Google’s own! This snippet ensures your WordPress website correctly calls the Google jQuery library direct from Google for speed, security and reliability:

// Use the google CDN version of jQuery
function wpfme_jquery_enqueue() {
wp_deregister_script('jquery');
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
wp_enqueue_script('jquery');
}
if (!is_admin()) add_action("wp_enqueue_scripts", "wpfme_jquery_enqueue", 11);

NB: Just make sure you use the above with…

wp_enqueue_script('jquery');

…in your header file, or wherever your wp_head scripts get called from.

Useful post? Share it

Leave a Reply

Your email address will not be published.