How to fix TypeError: $ is not a function in WordPress


We can guess. You purchased a theme or plugin and a console shown a message “TypeError: $ is not a function”? Ok, maybe you did not purchase anything and the TypeError was created with no reason or with manual customization. It doesn’t matter. What matters, how to fix the problem!

How can you fix the TypeError?

The first solution is to rename all references of $ to jQuery:

$( "a" ).hide(); to jQuery( "a" ).hide();

The second solution is to wrap your code using:

jQuery(function($) {
    ...your code goes here

Or you can simply add to the top of the problematic .js document (or to the tag):

var $ = jQuery.noConflict();

Using of jQuery.noConflict() function causes that $ is undefined and you are probably writing in a .js document $ in a front like this:

$(document).ready(function() { });

And you should be writing this:

jQuery(document).ready(function($) {
    // your code goes here 

WordPress may use $ for something other than jQuery and so you need to load jQuery in a different way. 

I hope that your problem was fixed with theses solutions. If your problem persists, leave a comment and we’ll try to help you.

Add comment

Recent Posts


Recent Comments