Wordpress & jQuery: “$ is not a function”

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();
});
  • Share/Bookmark

You can follow any responses to this entry through the RSS 2.0 feed.

Comments

  1. On September 09, 2009 Fabian says:

    Yeah, you saved my day!

  2. On November 05, 2009 Blair says:

    Sweetness! Somethings are too easy…for some people.

  3. On December 09, 2009 Matt Cassarino says:

    Nice, this helps a lot! Thanks.

  4. On December 14, 2009 Natasha says:

    Thank you so much for posting this, because I was at my wits end! :)

  5. On December 29, 2009 Matt says:

    Thanks; great reminder!

  6. On January 08, 2010 Andy says:

    Thanks, God Bless…

  7. [...] my wordpress theme’s (!) scripts. This turned out to be a jQuery problem, explained in a post here. Strangely enough editing the mv_embed script was not enough to fix the page, and the theme’s [...]

  8. On January 19, 2010 Nick says:

    Thank You So Much for this!!

  9. On January 23, 2010 Andrey says:

    10x a lot!!!

  10. On January 28, 2010 worldwisewebs says:

    wow so simple. Thanks :)

  11. On February 07, 2010 Rey Bango says:

    You should definitely consider using jQuery’s noConflict() method as another alternative.

    http://docs.jquery.com/Using_jQuery_with_Other_Libraries

    Rey – jQuery Team

  12. On February 10, 2010 Mark says:

    Whew… I was bashing my head on the keyboard already. Thanks!

  13. On February 11, 2010 Brian says:

    Thanks for this. Guess what? It works for Plone too!

  14. On February 12, 2010 Justin says:

    Thank you, most helpful!

  15. On February 24, 2010 droope says:

    Wow, thanks. :) That’s why,.

  16. On February 24, 2010 GChatzop says:

    Ty so much

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>