But I really want to use the variable

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.

Including jQuery in a WordPress plugin

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.

How To Become A Blogging Pro

How To Become A Blogging Pro

Save Hundreds Of Lost Hours and Thousands of Dollars in Lost Potential Earnings by Setting Your Blogs Up Right The First Time.

Get My Free Ebook


Post a comment