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.


Купить хостинг WordPress
WordPress tutor
Online tutoring services. List of courses I teach
  • Basic web design course;
  • Site layout;
  • General course on CMS WordPress and continuation of the course on template development;
  • Website development in PHP.
Read more on the page WordPress tutor
*/

Nikolaenko Maxim

Director of web studies ProGrafika. I am developing, website design and promotion. Always glad to new blog readers and good clients.


You may also like...

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Templates for WordPress
The best hosting in Ukraine
Stable hosting for Drupal