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?

  • 5
    if the location of jquery prevents your plugin from working, you're probably doing something wrong.
    – Milo
    Mar 22, 2013 at 1:50
  • 1
    +1 for Milo's comment. To expand on it: I can only speak for myself, but I'd consider it bad practice of a plugin author to force my WP to load jQuery in the <head>. I would venture to guess, that you simply enqueue your own scripts too early, read up on wp_enqueue_script and make them dependent on 'jquery'. Mar 22, 2013 at 15:00

1 Answer 1


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, 2013 at 13:59
  • just updated. There are a couple ways of doing it Mar 22, 2013 at 14:32
  • ReferenceError: jQuery is not defined. And indeed I continue to not understand why jQuery( document ).ready( function($){ should work when jQuery(function (){ fails. If jQuery is NOT loaded yet, any call to jQuery fails. Isn't it?
    – Toc
    Mar 22, 2013 at 14:39
  • The WordPress-bundled jQuery library is configured in no-conflict mode. Mar 22, 2013 at 19:10
  • Try to use: var jq = jQuery || $.noConflict()
    – Balas
    Jan 13, 2014 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.