TypeError: $ is not a function when calling jQuery function

 · 1 Minute Lesezeit

Let’s say you want to run a simple jQuery script that loads once the document is ready. Most people would just start with the following:

$(document).ready(function(){

    // Your jQuery code that's supposed to execute once Wordpress is ready

});

By default most WordPress installations should return: TypeError: $ is not a function But why? Because WordPress and theme developers load their jQuery instance in noConflict() mode, therefor the global $ shortcut for jQuery is not available. But no worries we have a fix!

Solution for the problem with WordPress

The solution for the issue is actually pretty simple, instead of using the code above use the following whenever you need to use jQuery in your WordPress theme:

jQuery(function ($) {
   // Your jQuery code for WordPress
});

Once you wrap your jQuery code in this you can keep using jQuery like your would normally, so for example:

jQuery(function ($) {
	$(document).ready(function(){
   		console.log($); 
   	});
});

That’s already it! If this solution not working for you, shoot us a comment with your issue or discuss your issue with other users in comments.