I’m going to be using a jQuery slider on my homepage only (not a WP plugin, but a third party). What I’d like to do is include jQuery, the plugin’s jQuery script using a .js file, then include the script needed to fire the plugin right before the closing body tag. I’m a bit confused about how that works.
I know WordPress comes with jQuery built in, so does that mean I don’t need to include it again?
Looking for best practices on this. I understand there are conflict issues that need to be prevented, etc.
Thanks
You typically should use the jQuery version that’s built in. There are instances where you might want to use wp_dequeue_script(‘jquery’) and then add a different version of jQuery.
Here’s the best way to add a script dependent on jQuery:
The third argument of wp_enqueue_script is the script dependency which we identify as jQuery. This guarantees that jQuery will be printed before your custom script is printed.
To add to that Brain said, you can use the
enqueue_script
function to add your js files to the footer if your theme useswp_footer
. Also when adding an action it is very useful when using javascript to use an order parameter so you can order them the way you wan’t.Something like:
You can also add it to the footer using
wp_footer
instead ofwp_print_scripts
http://codex.wordpress.org/Function_Reference/wp_enqueue_script