Load newer version of jQuery until WordPress Core has that version

⏲️ Time: < 1 min

jQuery version 1.9 was released today, and I wondered how one could use that version on my site until it was released properly with WordPress. I found out that the $wp_scripts variable holds the script version of registered scripts. Thus, I was able to concoct the following function for the wp_enqueue_scripts hook. Change the prefix as you see fit. Also change the version as you see fit as well. This is fairly future proof as versions will never go down.

add_action('wp_enqueue_scripts', 'prefix_load_scripts');
function prefix_load_scripts() {
	if(is_admin()) return;

	global $wp_scripts;

	if ( $wp_scripts->registered['jquery']->ver != '1.9.0' ) {
		wp_deregister_script( 'jquery' );
		wp_enqueue_script('jquery', 'http://code.jquery.com/jquery-1.9.0.min.js');
	} else {
		wp_enqueue_script('jquery');
	}
}

I won’t deny that I’m a believer in using the version of jQuery that WordPress comes packaged with, but if you are anxious to try out the new stuff and not worry about reverting back manually, this would be a way to go.


Michael is a seasoned developer who loves helping build stuff for the internet. He brings over a decade of varied experiences working with both front and back end developer stacks.

His primary focus has been WordPress and PHP and all the components that go along with them. During the day, he is a Support Engineer with WebDevStudios, helping clients get the best that they can out of their own websites.

Categories: Web Development

4 thoughts on “Load newer version of jQuery until WordPress Core has that version

  1. wycks says:

    And when 2.0 ships? …

    1. tw2113 says:

      Obviously I’d have to update this. 🙂

  2. foxpc says:

    Hi,
    first thanks fot the code. but i get error:
    PHP Parse error: syntax error, unexpected ‘&’
    in this line:
    if ( $wp_scripts-&gt;registered[‘jquery’]-&gt;ver != ‘1.9.0’ )
    i think it becuse -&gt;

    what i do wrong?

    thanks

    1. tw2113 says:

      Not your fault, mostly mine because I haven’t fixed encoding stuff. You need to change the > into > So you’d want:

      if ( $wp_scripts->registered[‘jquery’]->ver != ’1.9.0′ )

Leave a Reply

Your email address will not be published. Required fields are marked *

Webmentions