How to use an external jQuery plugin with Drupal's no-conflict jQuery I'm using drupal_add_js() to load some external js:

drupal_add_js('http://jquery-accordion.googlecode.com/svn/trunk/jquery.accordion.js', 'external');


This produces 'TypeError: $ is not a function' errors because Drupal uses jQuery in no-conflict mode. 

So I think the only solution is to copy the code, wrap it in this function and call it locally:

(function ($) {
  // Original JavaScript code.
})(jQuery);


I wondered whether there was a trick to still be able to directly use external js?
In Drupal 7, if you a certain that the external scripts are attempting to use "$" as an alias for jQuery, and you can't get the script author to patch their code, and you aren't loading any other JavaScript libraries, then in your template_preprocess_page, place the following drupal_add_js before the set of all drupal_add_js that reference external files. All scripts in the header region that use "$" as an alias will then refer to jQuery:

drupal_add_js('var $ = jQuery;', 'inline');


If your external javascript is added in another region, for example, the footer, then use something similar to the following instead:

drupal_add_js('var $ = jQuery;', array('type' =&gt; 'inline', 'scope' =&gt; 'footer'));