I am using the code below to include jQuery in my WordPress installation. I was previous calling the jQuery file using the standard HTML script but this was causing problems with a WordPress plugin in IE9. When I use the wp_enqueue_script function, it solves the problem but then it breaks my custom Javascript file which I include after wp_head(). What am I doing wrong?
<?php wp_enqueue_script("/wp-content/themes/mytheme/js/jquery-1.5.1.min.js"); ?>
<?php wp_head(); ?>
<script type="text/javascript" src="/wp-content/themes/mytheme/js/custom.js"></script>
1) Only include scripts via wp_head(). For your custom script, register and enqueue it as such:
2) You need to deregister core jQuery, and then register and enqueue your minified version, like such:
Note that both include a
if ( ! is_admin() )
conditional. You don’t want to mess with the scripts that load in the Admin UI.Also, my example uses Google for the minified jQuery version. If you want to use your own bundled version, add the SRC to
wp_register_script()
instead.Multiple issues here:
wp_enqueue_script()
usage (incorrect arguments);Basic example of doing it more properly would be something like this in
functions.php
of theme: