18 Aug 2009

WordPress & jQuery: “$ is not a function”

jQuery, Wordpress 96 Comments

If you are trying to add your own jQuery code to WordPress, and have had the error “$ is not a function” show up on Firebug, here is the fix:

Convert all dollar signs ($) to ‘jQuery’

The dollar sign is reserved in WordPress for the Prototype library, which is why it errors out. For example, instead of:

$().ready(function() {
   $("#select_me").show();
});

Change it to:

jQuery().ready(function() {
   jQuery("#select_me").show();
});

96 Responses to “WordPress & jQuery: “$ is not a function””

  1. Peter says:

    Add one more name to the list of people whose days you’ve saved with this article. Thank you! :)

  2. Scott says:

    Thank yOU!

  3. Joris says:

    What about this case? Do I change the code that’s between the php tags as well, or only $(document) into jQuery(document)…

    $(document).ready(function() {
    // ro map init
    javascriptMap.init({
    ‘mapUrl’: ”,
    ‘xmlUrl’: ”,
    ‘mapElm’: ‘#xmlMap’,
    ‘mapWidth’ : , // map width
    ‘mapHeight’ : , // map height
    ‘mapMargin’: ”
    });
    });

  4. chad says:

    Yes, the only thing you need to change is:

    $(document)

    to

    jQuery(document)

  5. Oli says:

    Thank you – got to love google search and people like yourself who care to post their fixes. Saved me a lot of time!

  6. T. Petersen says:

    Thank You!!!!!

  7. Dave says:

    This is more of theoretical question, but now that jQuery has won the javascript framework wars (based on popularity), why is it that we still reserved the “$” sign for Prototype? Sure, I used to use that framework myself, back in the day, but I haven’t touched Prototype in years, and I haven’t personally observed any WordPress plugins using Prototype. What do you think about just re-enabling the dollar sign in WordPress for jQuery?

  8. chad says:

    You bring up an interesting point that I fully agree with. Why do we have to find a workaround on something that 99% of users use in the first place? Maybe a stubborn WordPress team member is part of the other 1%…

  9. Brian K. Johnson says:

    Would this not work as well, to use the $ within the function($)?
    In that way, if you have a lot of other functions within your jQuery() it would save a bit of typing:

    jQuery().ready(function($) {
    $(“#select_me”).show();
    $(“#select_me”).etc();
    $(“#select_me”).etc();
    });

  10. Chris C says:

    YOU ARE A LIFE SAVER…thanks!

  11. Terri says:

    Thanks–worked!

  12. Petra says:

    Made my day. Thank you! :)

  13. Juergen says:

    Damn’, you are my hero.
    Who would have thought that solving this bloody error was so easy. Just doing a search and replace….
    Juergen

  14. goli says:

    jQuery(‘#leftsidebar,#page,#sidebar’).equalizeCols();

    still it is showing same error like jQuery(“#leftsidebar”, “#page”, “#sidebar”).equalizeCols is not a function

  15. chad says:

    goli, the issue is most likely with “equalizeCols”. Make sure you are spelling that correctly, and that the equalizeCols script is being loaded properly after jQuery is loaded in the header of your website.

  16. matt says:

    Why did I decide not to trust in a Google search sooner? Thank you, Chad. This saved the day. I’ve been going back and forth with a plugin developer trying to figure out where the conflict was and this was the trick.

  17. Josh says:

    I freaking LOVE YOU!!!! I was pulling my hair out on this one!

  18. Techno says:

    Thanks a ton. I had been trying to get around this for a couple or hours.

  19. Matt says:

    You just saved me like 3 hours of futzing around with code that was never broken. Thanks!

  20. PAT says:

    it also works in Magento phtml files if you put in some jQuery and have problems with the “is not a function” stuff.

  21. amir says:

    What if the $ sign is inside a library e.g: jquery.prettyGallery.js ? I can’t change all $ -> jQuery. There should be other easy solutions????

  22. amir says:

    If you don’t wish to change all $ into jQuery one by one this is another solution. by wraping all $ inside a (function($){ … })(jQuery)
    example:
    function($) {

    // we can now rely on $ within the safety of our “bodyguard” function
    $(document).ready( function() {
    alert(”hurrrrray! now we can use $ easily!”);
    } );

    } ) ( jQuery );

  23. Jordan says:

    Thank you! Was completely stuck on that one.

  24. sms says:

    my appreciation! thanks for ur help.

  25. Deacon Frost says:

    You save my life dude, thanks for the tip, I was so in the blind. lol crazy Prototype, glad it solved.

  26. marcus says:

    Amazing. Couldn’t work out what was going on and this saved my sanity.

    Thanks

  27. Ali says:

    Thanks Alot !!! you saved my day

  28. Alex says:

    thanks for the article. That worked for me

  29. early retirement options says:

    I have the same problem when integrating a mail-chimp form. Changing $ to jQuery fixed it. Thanks!

  30. Rafaël van Gurchom says:

    Do I need to change the “$” to “jQuery” in every script?
    For example i’m using jscrollpane plugin.
    Do I need to change all the dollar signs in jScrollPane.js too?

    Thank you on beforehand!

  31. Min says:

    You’re a live saver :)

  32. Evan says:

    Works perfectly. Thanks a bunch.

  33. Adi says:

    I’m glad I’ve found this page, you saved me a lot of time.

    Thanks a lot.

  34. boone says:

    Thanks, This came in handy after a WP upgrade (oddly my 2.x stuff was find with the $)

  35. Loiy Blog says:

    Help!
    I have changed $ to jQuery , but it still does not work.
    Please help me. thanks so much.

  36. chad says:

    What error message are you now receiving?

  37. Rodrigo says:

    I you were here in Chile, I would invite you a cup of red wine. Thanks! it works fine.

  38. Luis Siquot says:

    Great and consise!!!!

  39. Kris says:

    It works as a solution of the jquery problem in magento. It is more detailed too.

  40. Susan says:

    thank you!!!

  41. Colin says:

    Thanks! Stupid prototype! X(

  42. Tom Fox says:

    You are the Don.

  43. Marco says:

    You made my day :-D

  44. Erica says:

    Great!
    Thank you!

  45. Jules says:

    THANKS!!!!! just what i needed after hours of searching

Leave a Reply