WordPress & jQuery

WordPress & jQuery

[Update] The generally accepted best practice is to no longer do this or use a plugin. More information in the WordPress codex

The release of jQuery 1.4 brings many javascript improvements in performance, better handling of attributes, manipulation of DOM events and many more. Head over to the jQuery site for more details and a breakdown of the new features and improvements.

That’s great and we all like speed and flexibility improvements. Now, how would you like these in your blog from today? Well a very quick and easy modification to your theme can have you utilizing the latest version of jQuery from Google’s CDN servers. I took the code block from the source site below, inserted it in my functions.php but replaced the jQuery version number. Check out the adjusted code block below:

if( !is_admin()){
   wp_deregister_script('jquery');
   wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, '');
   wp_enqueue_script('jquery');
}

See where I just put “..jquery/1/jquery…” – by referencing the “1” instead of “1.3.2” we will get the latest version of jQuery loaded on the site. A quick look at the source code and we can see that the inserted javascript source is indeed via Google’s CDN and by clicking on the source code we see it’s version 1.4. To use simple terms in this code we are telling WordPress to “forget” it’s usual jQuery source / script setting, then preparing WordPress for the new settings (please load jQuery from Google’s CDN) and then serving up the new information for WordPress to use.

A quick and easy way to give your blog / site the benefits of the recent jQuery updates and improvements. If you encounter an issue with your site or  jQuery after this change you can easily revert to the previous version (1.3.2) by either removing the code block you added or, to keep jQuery hosted by Google’s CDN, adjusting the version number from “1” to “1.3.2”. For those more familiar with jQuery coding there’s a list of “backwards incompatible” changes settings on the jQuery site.

If you’ve changed your site over to jQuery 1.4 how did it work out? As smoothly as mine did? Leave me a comment.

Source: http://digwp.com/2009/06/use-google-hosted-javascript-libraries-still-the-right-way/


8 Comments

How to use jQuery 1.4 by default on your WordPress blog · January 18, 2010 at 12:17 am

[…] a lot to Sean Hayes for sharing this tip with […]

jQuery 1.4 and WordPress 3.0 | the rabbit hole · January 18, 2010 at 12:32 am

[…] Sean Hayes for the original tip. No Comments | Leave a comment » No comments or pings yet. RSS feed for comments on this post. | TrackBack URL Your NameJanuary 18, 2010 at 1:32 am | Permalink | Live Comment Preivew Leave a comment Click here to cancel reply. […]

¿Cómo usar jQuery 1.4 por defecto en WordPress? | HyperCODE · January 18, 2010 at 12:53 am

[…] Vía: Sean Hayes […]

Usa la última versión de jQuery automáticamente | Ayuda WordPress · January 18, 2010 at 2:34 pm

[…] usas jQuery en tu sitio creado con WordPress y quieres siempre disponer de la última versión, y que encima no tengas que alojarla en tu servidor sino que la cargue directamente desde los […]

Use a última versão do jQuery automaticamente no seu tema | Ajuda Wordpress em Português · January 19, 2010 at 4:15 am

[…] by WP Greet Box WordPress PluginSe você usa jQuery no seu tema de WordPress e quer ter sempre a última versão do querido jQuery, mais não quer hospedar no seu  servidor e sim carreguar diretamente desde os servidores de alta […]

Using jQuery as Default on WordPress # WordPress Tricks & Tips · January 19, 2010 at 6:23 am

[…] will be replaced by latest version 1.4 and up that taken from Google Apis, this trick is share by Sean Hayes and I got this nice trick from WP […]

Cómo usar siempre la última versión de jQuery en WordPress · January 19, 2010 at 5:12 pm

[…] Vía | Sean Hayes […]

Como usar o jQuery 1.4 no seu blog WordPress · January 20, 2010 at 2:26 pm

[…] para o Sean Hayes. Obrigado por compartilhar a dica conosco, […]

Leave a Reply

Avatar placeholder