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?


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

  • 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

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/

  • 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

This should work, I believe:

var $ = jQuery.noConflict();
  • 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

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

    // you can use $ here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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