1 2 3
Using Chrome’s Developer console (i.e., hit F12) to view the Resources for the page, I could see that jQuery is being loaded. I wanted to load jQuery from Google’s Content Delivery Network (why?). My initial attempt was to simply change the jQuery reference to the CDN location (I also upgraded to version 1.7.1 while I was at it):
This worked, and Chrome’s Developer console showed that jQuery was being loaded from the CDN. However, there was another problem. WordPress apparently also loads jQuery by default, so the page ended up with an extra copy.
To remove the redundant copy, I removed the jQuery references from the header.php script, then added the following lines to the functions.php script in the theme folder which use WordPress’s built-in function wp_enqueue_script to ensure that only one copy of jQuery is included.
1 2 3 4 5 6
This worked and only a single copy of jQuery remained. However, the other scripts which depend on jQuery now break because they are being loaded before jQuery.
Following the instructions provided in the wp_enqueue_script reference, I added the following lines to functions.php to ensure that their dependency on jQuery is enforced:
1 2 3 4 5 6 7 8 9 10 11 12 13
The corresponding references, of course, should be removed from header.php.
Finally, verifying with the Developer console shows that everything is loaded correctly.