Because the jQuery object is used so often, having a short alias is very useful and the dollar sign is so conventional that when people are looking at jQuery code, they are often looking for this dollar sign as an indicator that the jQuery object is being used.
Now we could use a simple assignment to say
$ = jQuery
and just leave it at that, but the issue is that we don't know if the dollar sign is being used by some other JavaScript library ... So in order to make sure that the dollar sign doesn't get overridden somewhere along the lines, we need to make the dollar sign a local variable for each function that we writeSource: BuildAModule: How to use the dollar sign as an alias for the jQuery object
WordPress ships with its own version of the jQuery library ... in compatibility mode by default. That means that the typical
$
shortcut for jQuery doesn't work, so it doesn't conflict with any other JavaScript libraries that use the dollar sign also, like MooTools or Prototype.Many plugin authors and theme developers are aware of this, and they use
jQuery
instead of$
to be safe ... Let's stop doing that.If the script is being loaded in the footer ... you can wrap the code in an anonymous function where you pass in
jQuery
to be mapped to$
.
Always when trying to integrate a Mailchimp Newsletter Subscription into WordPress manually, there are a lot of problems occuring
- Avoid jQuery conflicts and problems
Replace the dollar signs (
$
) in the jQuery-Javascript code with (jQuery
), especially the functionmce_success_cb
is responsible for a lot of problems otherwise.Source: WordPress and Mailchimp: Custom Newsletter Subscription Form
// Pen deleted..
// codepen_embed height="800" theme_id="0" slug_hash="yMXVrw" default_tab="js" user="dotherightthingnz"]