Uncaught TypeError: $ is not a function в WordPress. How to fix it quickly?
Very often, when developing a new site or developing a theme, we see an error “Uncaught TypeError: $ is not a function”, in WordPress it is generally a classic. The problem occurs because WordPress uses the conflict-free jQuery syntax., this means that in the code you need to write instead of the dollar sign $ jQuery text.
1. The first way to solve the problem with “Uncaught TypeError: $ is not a function”
$(window).ready(function() {
Need to write like this:
jQuery(window).ready(function($) {
// code
}
Then inside the code will be executed with a dollar sign, well, or just write jQuery instead of the dollar.
2. The second way to solve the problem with an error “Uncaught TypeError: $ is not a function” and automation solutions for WordPress
Not so long ago I had an idea how not to change everything $ on jQuery and found a very simple solution to this problem. In the functions.php file, you need to add this code and everything else will work fine.
wp_add_inline_script( ‘jquery’, ‘$ = jQuery;’ );
If my solution seemed great to you or you have a better solution, write in the comments I will be glad.
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.