I've written a plugin which uses wp_enqueue_script("jquery");
to load jQuery. I need to load jQuery in the head and not at the bottom of the body. However, I think that this command is overwritten by some theme which loads jQuery at the bottom of the body so preventing my plugin to work properly. How can I force WP to load jQuery in the head?
Edit: new solution, based on one of the comments. If you are using wp_enqueue_script
to load your js file, make sure jQuery
is a dependency so that it gets called before your code:
wp_enqueue_script( 'my_script', 'my-script.js', array( 'jquery'), $ver, true );
You can then remove the original enqueue call you had since jQuery
will be included automagically
-
Apart that your command is a syntax error according to the page you cite, if my script fails because jQuery is not loaded, how can it not fail calling jQuery(...) as you suggest? Anyway, it does not work. – Toc Mar 22 '13 at 13:59
-
-
ReferenceError: jQuery is not defined. And indeed I continue to not understand why
jQuery( document ).ready( function($){
should work whenjQuery(function (){
fails. If jQuery is NOT loaded yet, any call to jQuery fails. Isn't it? – Toc Mar 22 '13 at 14:39 -
The WordPress-bundled jQuery library is configured in no-conflict mode. – Chip Bennett Mar 22 '13 at 19:10
-
<head>
. I would venture to guess, that you simply enqueue your own scripts too early, read up onwp_enqueue_script
and make them dependent on'jquery'
. – Johannes Pille Mar 22 '13 at 15:00