TypeError: $ is not a function when calling jQuery and its functions in WordPress

Are you using jQuery functions in WordPress ad getting error ” $ is not a function “?

Well this is the error faced my many who start to work with WordPress but if ewe dig deep, this is just happening because jQuery used in WordPress by default work with the jQuery not $ for preventing conflicts with other frameworks.

Bellow is the example on how you should use jQuery in WordPress

You might be getting error if you are using this :

    // jQuery code is in here

You can simple resolve the error by replacing $ with jQuery like below :

    // jQuery code is in here

and just after the above change you will find the code working.

Due to some reason you don’t want to use jQuery keyword specifically?

There is still a way around. You can create your own no conflict keyword to use in place of $ and jQuery. Have a look at the no-conflict code below for jQuery:

var yourkeyword =jQuery.noConflict();
  alert("Hi this will not conflict now");

Don’t forget to replace yourkeyword with your own word.
Always Feel free to comment if stuck somewhere

Leave a Comment