Disabling jQuery No Conflict Mode in WordPress
20 October 2012
The bundled WordPress jQuery ships in noConflict()
mode (only supporting the jQuery
variable), meaning any jQuery that uses $
doesn’t run. Although wrapping it in a function that passes the variable as an alias works, it doesn’t work for scripts you include from elsewhere that might use the $
. Plus it’s a massive headache. If you’re sure you’re not using any other libraries that would conflict, here’s how you bring $
back.
Straight after <?php wp_head(); ?>
in header.php enter:
[codesyntax lang=”javascript”]
<script>var $ = jQuery.noConflict();</script>
[/codesyntax]
Now just make sure your other scripts are included below that line. If you’re using wp_enqueue_script
, you could also include this code in a separate file and set is a dependency for your other scripts.