Tag: jquery

Integrating WordPress and Google-hosted jQuery 1.4

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_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, '');

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/

WordPress and jQuery

A recent client project increased my exposure to integrating jQuery with WordPress.

For this client I had to design a filter interface enabling the user to choose a category and then pick a time range to search for rated posts (if not all time) and then finally the resultant posts are sorted by ratings. For the ratings the site already used the excellent plugin WP-Post ratings from Lester Chan. I made minor tweeks to this plugin so it could search for rated posts based on the date they were posted (rather than the date they were rated).

I utilised jQuery to perform the category highlighting, date selection and to inject the results in the page without a page refresh. Very neat and visually appealing I know, like most other developers that jQuery will be used more and more.