You should not use the $ variable for jQuery within WordPress. OK, I know, you've got a good reason. Say for instance, you're copying a jQuery script over from another non-WordPress project and it's proving cumbersome to covert all the $ variables to jQuery or some other custom shortcut variable. Fine. (Never heard of "Find and Replace"?) At any rate, here is an example of how to shortcut jQuery to safely use the $ variable:
The only drawback to the above solution is, I've found it's easy to start working with the $ variable and then forget to encapsulate other scripts in the above jQuery function. If all my jQuery scripts use the jQuery variable or a custom variable (such as $jq), I'm much better at staying in noConflict mode.
You can include jQuery in a WordPress plugin using any of the earlier mentioned methods. However, you'll need some familiarity working with WordPress plugins. We'll cover this topic in detail by learning more about WordPress plugins later in Chapter 3, Digging Deeper: Understanding jQuery and WordPress Together.
Was this article helpful?