Tips / Recommendations

jQuery is Not Defined in WordPress

Step 1: Inclusion of jQuery Library

When you go through code, make sure that jQuery is included and will load before your script. Even, the jQuery should be loaded once only. If it is loading multiple times, it will cause problems.

If it is not included, then pass it as third argument in your wp_enqueue_script () function as follows:

wp_enqueue_script( 'tt-mobile-menu', get_template_directory_uri() .

'/js/mobile-menu.js', array('jquery'), '1.0', true );

Step 2: Structure of JavaScript File

Secondly, you will make sure that your JavaScript will start as follows:

jQuery(document).ready(function()

{

jQuery(#selector) ...

});

(function($) {

// Use $() inside of this function

$(#selector) ...

})(jQuery);

Step 3: Ensure that jQuery is Loaded

Sometimes, there are issues because the jQuery is not loaded though included. So to make sure that jQuery is loaded, copy the URL from script src and paste it in the new browser tab. For example: If the script src is this:

<script src="http://code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script>