-
Tom posted an update: 2 years, 0 months ago
I can’t any of my custom jquery to work without calling googleapi jquery after WP_head. Do I remove jquery from bp and load it myself, or can I get the jquery that bp loads to do it by some special magic? Please help >_<
Andrew Wayne posted a new activity comment: %s @andy i would like to know this also..cant seem to get it to work
Micha? M posted a new activity comment: %s use wp_enqueue_script() to load a script with dependencies.
e.g. wp_register_script(’my-script-name’, plugins_url(’/plugin-name/js/my-script.js’), array(’jquery’));
the last parameter is and array of script names that your script depends on.
there’s a list of included script names along with full documentation here: http://codex.wordpress.org/Function_Reference/wp_enqueue_script
also, jquery won’t always be available as ’$’ in wordpress. use ’jQuery’ or wrap your script in a function to set $ locally:
(function($) {
$(’a’).css(’color’, ’red’);
})(jQuery);
Tom posted a new activity comment: %s So if I use this then 1. I won’t have to activate jquery manually for my ”extra” jquery plugins and 2. I shouldn’t have a conflict with current jquery javascript that breaks things like the avatar cropper?
@tmort
1. yes. if you specify dependencies wordpress loads them automatically.
2. yes. wordpress loads these libraries in a way that avoids conflicts.
i just noticed i wrote wp_register_script instead of wp_enqueue_script.
Finally got it to work, thank you so much for the help!