Snippet: Using jQuery 1.5 in WordPress

Hey there! I'm currently working on a CLI tool to deploy WordPress apps to DigitalOcean. Check it out! It's free and open source.

Yes! jQuery 1.5 was released and I’m sure some of you can’t wait to start using it in their WordPress themes and plugins. So, with a few filters magic, we can get jQuery 1.5 up and running. Add the following code to your theme’s function.php file:

add_filter( 'script_loader_src', 'my_script_loader_src', 10, 2 );
function my_script_loader_src( $src, $handle ) {
    if ( $handle == "jquery" )
        return "";
    return $src;

And that’s it! Now every call to wp_enqueue_script jquery will pass through this filter and load up 1.5 instead of the one shipped with your WordPress bundle. Feel free to change the URL of the jQuery script to different CDNs including Microsoft’s and Google’s.

I guess this post will be outdated upon the next WordPress release, but it still may be valuable, since the same trick is used to run jQuery and other libraries shipped with WordPress from different sources like Google or Amazon CloudFront.

10 thoughts on “Snippet: Using jQuery 1.5 in WordPress

  1. Tweets that mention Snippet: Using jQuery 1.5 in WordPress --

    • Johnny, good questions. I believe filters are faster than deregister/register calls. Also, your version enqueues the jQuery script, while my version says rewrite to 1.5 if and only if jQuery is asked for (by themes or plugins). But anyways, perhaps this needs some profiling and benchmarking. Thanks for your input!

  2. jQuery 1.5: Novedades, Descargas, CDNs y uso en WordPress

Comments are closed.