Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Honestly, I'd suggest using a different plugin, then. Or at least forking that plugin and rewriting the javascript to actually work with WordPress. –  John P Bloch May 6 '11 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. –  John P Bloch May 6 '11 at 15:09
    
Is there not just a way to use $ in wordpress? –  Mild Fuzz May 6 '11 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. –  John P Bloch May 6 '11 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. –  John P Bloch May 9 '11 at 13:16

3 Answers 3

up vote 4 down vote accepted

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/

share|improve this answer
    
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 May 6 '11 at 12:05

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

jQuery(document).ready(function($){
    // you can use $ here
});
share|improve this answer

This should work, I believe:

var $ = jQuery.noConflict();
share|improve this answer
    
placed anywhere? –  Mild Fuzz May 6 '11 at 13:39
    
Placed above where you want to use $ –  Chris_O May 6 '11 at 14:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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