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.