Using jQuery in your WordPress theme
Just updated my theme on my wordpress powered greendale.tk blog. As jQuery is now part of wordpress, I figured I should get rid of the Mootools scripts I was using and rewrite them in jQuery. Nothing against mootools, but the integration is better now with jquery, and I am now more familiar with jQuery as I use it a lot in my asp.net mvc apps. Also it didn’t always play nice with other plugins.
Anyway, I ran into a few issues, and I thought I’d share them here in case anyone else ran into those as well.
As long as you use Mootool and not jQuery this works fine, but if you want to include jQuery you should use this to play along nicely with other plugins or scripts that use jQuery:
The wp_enqueue_script command ensured everything is loaded in the right order. If you use the bloginfo command and insert the script yourself, chances are you end up loading your own script before jQuery is loaded ! Which ofcourse results in all sorts of weird errors. The eric-jquery is my own script, the lightbox stuff is for the excellent jQuery lightbox plugin. There are a few lightbox jQuery plugins, but I liked that one the best.
Something else you want to keep in mind. Do not use the $(“#archive_result”) jQuery selectors, but use jQuery(“#archive_result”). Something like this:
jQuery-ui has some things I might like to add later, for now I just rewrote some of the simple sliding things on the sidebar and the archive page.