TypeError: $ is not a function WordPress TypeError: $ is not a function WordPress wordpress wordpress

TypeError: $ is not a function WordPress


You use jQuery.noConflict(); So $ is undefined.

You can read more about it here docs

Try to modify your code in this way (add $ sign to ready function):

jQuery(document).ready(function($) {    // Code that uses jQuery's $ can follow here.});


Function errors are a common thing in almost all content management systems and there is a few ways you can approach this.

  1. Wrap your code using:

    <script> jQuery(function($) {YOUR CODE GOES HERE});</script>
  2. You can also use jQuery's API using noConflict();

    <script>$.noConflict();jQuery( document ).ready(function( $ ) {// Code that uses jQuery's $ can follow here.});// Code that uses other library's $ can follow here.</script>
  3. Another example of using noConflict without using document ready:

    <script>jQuery.noConflict();    (function( $ ) {        $(function() {             // YOUR CODE HERE        });     });</script>
  4. You could even choose to create your very alias to avoid conflicts like so:

    var jExample = jQuery.noConflict();// Do something with jQueryjExample( "div p" ).hide();
  5. Yet another longer solution is to rename all referances of $ to jQuery:

    $( "div p" ).hide(); to jQuery( "div p" ).hide();


Instead of doing this:

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

You should be doing this:

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

This is because WordPress may use $ for something other than jQuery, in the future, or now, and so you need to load jQuery in a way that the $ can be used only in a jQuery document ready callback.