Buddypress jQuery is not defined error

December 16th, 2009 by Peter Anselmo Leave a reply »

While developing a Buddypress plugin, I was running into a problem where none of my Javascript was working. Instead, Firebug was telling me: “jQuery is not defined”.  This was quite frustrating, as I could verify that the jQuery file was indeed, being loaded.  While a few other people received the same error for different reasons (corrupt files, etc.) I did not quickly find the solution for my problem.  Here it is:

Problem: Buddypress calls your plugin’s JS files BEFORE jQuery files.
This applies when you use the function wp_enqueue_script() – as you should.

Solution: Tell wp_enqueue_script your file depends on jQuery.
It turns out, wp_enqueue_script() takes a few optional parameters – the third being an array of other js files yours is dependent on.

Here’s how the call looks after the change:
wp_enqueue_script(‘my-js-file’,’my-file-path.js’,array(‘jquery’));

Viola!  Your js file is now loaded after jQuery and you’re good to go.

4 comments

  1. Nathan says:

    Thank you for code-zen! I’ve turned here a number of times when I couldn’t figure out what was going on (e.g. Using Custom Profile Field Data in Buddypress Templates)

    I have an issue right now with Buddypress 1.2.3, on WPMU 2.9.2, which I thought your wp_enqueue_script solution in this post would solve. It has something to do with how wordpress or buddypress deal with javascript.

    I’m trying to install this jquery slider on a child theme, and it’s acts as if javascript were turned off…

    The slider is here: http://cssglobe.com/post/5780/easy-slider-17-numeric-navigation-jquery-slider

    I’ve tried a few other javascript plugins, and none of them seem to work on this site.

    I tried:

    I wonder if you would have any ideas what might be going on? My php & javascript chops are limited.

    It also might have to do with this topic:
    http://buddypress.org/forums/topic/slider-jcarousel-jquery-not-working-on-latest-buddypress

    Thanks again for a great resource!

  2. Hi Nathan,
    Thanks for stopping by! I hadn’t come across that slider before, it looks pretty sweet. Can you post a URL of your site where it’s not working? I might be able to glean some info about what’s going wrong.

  3. Nathan says:

    Sure thing, Peter:

    http://otherhood.artmonks.net/american-decadence/

    This is a child blog that uses a child of the default BP Theme. Eventually, I’d like to get all the authors/artists listed (with their xprofile info) to show up in a slider.

    Interestingly, you’ll see I added the WP Carousel jquery plugin, just for kicks, and that DOES seem to work (I think it has its own jquery calls), but it’s not what I need (unless I tweak it somehow to display bp_member_profile_data).

    Here’s a description the big picture of what I’m working on, if it’s interesting or useful to you: http://buddypress.org/forums/topic/how-to-get-xprofile-data-to-show-up-on-child-blogs-eg-author-name-and-bio#post-47421

    Thanks!

Leave a Reply