WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to use jQuery in my Wordpress plugin. I'm trying to load the jquery library using the enqueue script but its throwing an error.

Error: $ is not a function

Here's the code snippet that's inside my main plugin.php file...

function ($post)
    <script type="text/javascript">
    function doTestParse(searchString){
        var rx = new RegExp('(?![^<]+>)'+searchString, "gi");
        $(this).html($(this).html().replace(rx, '<b>$&</b>'));
<?php ?>
share|improve this question
up vote 4 down vote accepted

jQuery is included in noConflict mode in WordPress, so you can't use the shorthand $, but must write jQuery(this).html(jQuery(this).html().replace(rx, '<b>$&</b>'));

share|improve this answer
Thanks Jan, does <b>$&</b> become <b>jQuery&</b> ? – Scott B Nov 3 '10 at 19:56
@Scott: html() returns a Javascript String object, and replace() is a standard function. &$ means "the matched substring" in this context, so the $ has nothing to do with jQuery and has to stay. – Jan Fabry Nov 3 '10 at 20:17

I am not sure when exactly your code fires, but it is good practice to add enqueue directives to init hook, instead of trying to call them in-place.

wp_enqueue_script docs in Codex have plenty of useful examples on topic.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.