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 :

$(document).ready(function(){

    // jQuery code is in here

});

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

jQuery(document).ready(function(){

    // 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();
yourkeyword(document).ready(function(){  
  alert("Hi this will not conflict now");
  yourkeyword('selector').show();
});

Don’t forget to replace yourkeyword with your own word.

Always Feel free to comment if stuck somewhere

Authored By :

I am a Sr. Web Developer passionate about blogging and teaching. When I am not coding or writing blogs, I prefer traveling (Which I like most). I am also doing a bit or research on Indian Startups now a days.


Leave a Reply

Your email address will not be published. Required fields are marked *