Apr
02
2010
Force WordPress to use the Latest Version of jQuery
If you’re using WordPress 2.9.x, then the latest version of jQuery included is 1.3.2. What if you want to take advantage of new features in version 1.4, like delaying an animation queue or binding multiple event handlers? You can easily add a link in your header to the latest version, but that might end up conflicting with some plugins or themes.
The best approach would be to use the following piece of code to let WordPress know that you want to load the current version instead.
Place this into your theme’s functions.php file:
function current_jquery($version) { global $wp_scripts; if ( ( version_compare($version, $wp_scripts -> registered[jquery] -> ver) == 1 ) && !is_admin() ) { wp_deregister_script('jquery'); wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/'.$version.'/jquery.min.js', false, $version); } } add_action( 'wp_head', current_jquery( '1.4.2' ) ); // change number to latest version |
If jQuery is updated, all you have to do is change the version number when calling the function.
Reference: Binary Bonsai



That’s some strong kung-fu… Love it! I hate including my own version of jquery in my themes and hardcoding their path in. Now I can do it the right way =)
Thanks for modifying the code from Binary Bonsai as it didn’t work on my template.
However, I’ve found that if you specify an earlier jQuery version in the function (eg 1.2.6), then WordPress still loads the earlier version instead of the more recent bundled version.
Does this mean the version check doesn’t work?
For some reason, $wp_scripts stops working when you call it in this instance, so the version check always equals 1. I have done some testing and I can’t for the life of my figure out why all of a sudden $wp_scripts no longer contains any values.
The script still works, but it will always load whichever version you state instead of actually checking which version is already installed.
if you use wp_enqueue_script rather than wp_register_script work
Thanks, c. It’s still a useful function nonetheless.
Great post. I use yours method. Thx…
Great, it seems to be exactly what I need but I don’t know where should I paste that code?.
I’m a newbie in wordpress. Thx
The only place you should be messing around is in your theme’s directory. Look to see if you have a
function.phpfile in there. If not, create it and then paste the code above into it. Then use the wp_enqueu_script() function in theheader.phpfile.You should rename this post to “Force Your WordPress Theme to Use the Latest Version of jQuery”.
Yes i am using wordpress 2.9.x and was searching for the best tutorial for adding updated version of JQUERY since wordpress 2.9.x contains JQUERY 1.3.2 version but I felt disappointed since I didn’t found any good tutorial at last your tutorial had satisfied me since it worked for me well. I hope this code will really help many people since everyone looks for updated version.