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 Profits Unleashed

Blogging Profits Unleashed

Already know that blogs are an essential element of your online business but just don't know HOW to gain a slice of the pie? Discover What You Need To Know About Setting Up and Running a Successful and Profitable Blog, Quickly and Easily.

Get My Free Ebook


Post a comment