WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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 have a jQuery script that works fine within a WordPress post as long as I include a reference to the jQuery libarary within the post.

<script src="http://code.jquery.com/jquery-latest.js"></script>

From what I have read this is not the proper way to reference jQuery as it is already included within WordPress (using v3.4.2).

If I remove the inline reference the script fails and the console says that "$" is undefined. I also tried replacing "$" with "jQuery" according to articles that talk about NoConflict mode in jQuery.

My jQuery script can be viewed here in jsFiddle.

share|improve this question
up vote 2 down vote accepted

In order to use $ inside your script (You only need to change the wrapper of your script), use the following wrapper.

jQuery(document).ready(function($) {
    // $() will work as an alias for jQuery() inside of this function

Make sure you enqueue jQuery in one of your plugins or theme using wp_enqueue_script('jquery');

Read more on Codex


The following article contains useful tips on using jQuery with WordPress.


share|improve this answer
+1 Thanks! That worked great. I changed the wrapper of the script and added the wp_enqueue_script('jquery'); to my functions.php file in my theme using the method explained in WP codex link you posted. – webworm Dec 10 '12 at 2:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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