1

Adding scripts for my theme and added jquery as a dependency. I see the jquery script tag in the header of the page but my script in the footer is getting a "$ is not a function" error.

function wpdocs_template_scripts() { wp_enqueue_style( 'style', get_stylesheet_uri() ); wp_enqueue_script('modernizer', get_template_directory_uri() .'/js/vendor/modernizr-2.8.3.min.js', null, null, false); wp_enqueue_script('bootstrap', get_template_directory_uri() .'/js/bootstrap.min.js', array('jquery'), null, true); wp_enqueue_script('main', get_template_directory_uri() .'/js/main.js', array('jquery'), null, true); } add_action( 'wp_enqueue_scripts', 'wpdocs_template_scripts' ); 

1 Answer 1

2

Put this in your .js file

(function($) { // Your code inside here; })(jQuery); 

This is called an anonymous function, you're passing the jQuery object as a parameter to it.

OR

 var $ = jQuery; // This at the top of the file 

This is simple, you're just assigning the jQuery object to the $ variable

References:

is-not-a-function-jquery-error

jquery-is-not-a-function-error

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.