jQuery inluclude still seems ncessary for script to work within post

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>

Read More

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.

Related posts

Leave a Reply

1 comment

  1. 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

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

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

    http://www.ericmmartin.com/5-tips-for-using-jquery-with-wordpress/