Listing 7-20 shows how to add the built-in jQuery and UI core libraries to your theme.
Listing 7-20. Including jQuery
Using jQuery in WordPress is a bit tricky. Most jQuery scripts rely on a dollar sign function. For example, $("div.main").addClass("wide"); would add the wide class to a div that already had the main class. However, several other libraries, including Prototype, use this same convention. Because WordPress also uses Prototype, the jQuery library is loaded in "no conflict" mode (docs.jquery.com/Using_jOuery_with_Other_Libraries).
You have two options. You can use 'jQuery' in place of the dollar sign function ('$') throughout your script, or you can wrap your script in an extra function. Both methods are shown in Listing 7-21.
Listing 7-21. Using jQuery in WordPress jOuery("div.main").addClass("wide");
// $() will work inside this function; otherwise use jOuery() $("div.main").addClass("wide");
Was this article helpful?