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.

Blogging Bounty

Blogging Bounty

Finally Learn How To Use Your Blog As A Cash Machine And Stop Wasting Your Time! This Book Is One Of The Most Valuable Resources In The World When It Comes To The Network Marketers Guide To Leads Through Blogs!

Get My Free Ebook


Post a comment