Replace WordPress jQuery with SAME VERSION of Google jQuery | Web Development Services by Ed Nailor

Replace WordPress jQuery with SAME VERSION of Google jQuery

Print Friendly

There are a number of online tutorials and code snippits designed to help you replace the WordPress core loaded jQuery with the hosted version of jQuery from Google. I love the idea as it gives me one less item to load locally and therefore can help speed up the website. I also like having multiple options for loading a script, just in case one is broken.

What makes this different? Most scripts make you define the version of jQuery you want to use in your theme or plugin, or use the lastest version. However, this can be a problem.

In my own framework, I was loading 1.7.2 with the code I used. With the update to WordPress, the current version was 1.8.3 while the latest version at Google was 2.0.0.

Using an older version of jQuery may cause issues with WordPress functionality, while using one not yet supported by WordPress is likely to cause other issues. So how do you load the current version from WordPress without having to go back and update the code with each WordPress upgrade?

Enter $wp_scripts. The $wp_scripts is a global variable that holds all the registered scripts that will be used in the site. By getting into this variable, we can find the current version loaded and then call for that same version at Google.

Here is how I use this new information:



Comments are closed.