1

I have a plugin I want to use, but it depends on the $ identifier, as apposed to using jQuery.

Is it possible to enable the $, to save me recoding the plugin?

EDIT

The plugin automatically adds the javascript, therefore I can't wrap it.

6
  • Honestly, I'd suggest using a different plugin, then. Or at least forking that plugin and rewriting the javascript to actually work with WordPress. Commented May 6, 2011 at 15:08
  • Also, if you could add a link to the plugin, we could maybe give you advice on the easiest way to hack the plugin to work correctly. Commented May 6, 2011 at 15:09
  • Is there not just a way to use $ in wordpress?
    – Mild Fuzz
    Commented May 6, 2011 at 15:10
  • de-register jquery and then re-register your own copy without noConflict mode. You risk breaking a lot if you do that, though. Commented May 6, 2011 at 15:52
  • 1
    As long as you kept the version of jQuery you're using identical to the one WordPress uses, you shouldn't have any problems. For example, using jQuery 1.5.x in WP 3.1 breaks almost everything in the admin area. Commented May 9, 2011 at 13:16

3 Answers 3

5

Try this:

jQuery(function ($) {
    /* You can safely use $ in this code block to reference jQuery 
           Call your plugin here
       */
})

I think you already know this. But still for reference http://api.jquery.com/jQuery.noConflict/

1
  • Also you can try var $ = jQuery; in the first line of the plugin. Sometime when i need to change all instance of $ to jQuery in a function. i just use it in the first line of the function and it works for me :) Thanks!
    – Sisir
    Commented May 6, 2011 at 12:05
2

This should work, I believe:

var $ = jQuery.noConflict();
2
  • placed anywhere?
    – Mild Fuzz
    Commented May 6, 2011 at 13:39
  • Placed above where you want to use $
    – Chris_O
    Commented May 6, 2011 at 14:26
1

The code Sisir provided would work, or you can use this code:

jQuery(document).ready(function($){
    // you can use $ here
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.