WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am fairly new to using jQuery in WordPress and I am trying to write jQuery scripts in a separate file.

What is the difference between the following two syntaxes of setting up the external file:

Version I

jQuery(function() {

Version II

$(document).ready(function() {
share|improve this question

closed as off topic by kaiser, s_ha_dum, Johannes Pille, brasofilo, Wyck Mar 20 '13 at 16:23

Questions on WordPress Development Stack Exchange are expected to relate to WordPress within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

whats WordPress got to do with this question? – Bainternet Mar 20 '13 at 11:17
Agreed, @Bainternet - it ain't WP specific at all. However, if you encounter noConflict mode for the very first time with WP, I can see why it would seem as if it was. – Johannes Pille Mar 20 '13 at 11:26


jQuery is included in WordPress in noConflict mode, so as to work with other javascript extensions that also use $ as an alias.

Hence your above Version II will not work with the WP native jQuery loading.

What is jQuery?

jQuery is not a language. It is nothing but a (massive) javascript object. That object's name is jQuery. When .noConflict() is not applied, $ is an alias for the jQuery object.

Best practice for external files

Wrap the entire js in a closure, pass it the jQuery object and $ as an argument. Inside you can write your script the way you're used to:

    $(document).ready(function() {
share|improve this answer

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