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.


2 Answers 2


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:

function theme_register_scripts(){
   wp_enqueue_script('myscript-name', get_bloginfo('stylesheet_directory') . '/js/myscript.js', array('jquery'));
add_action('wp_print_scripts', 'theme_register_scripts');

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.

  • So that handles including jQuery (using the built in WP version) and my jQuery plugin file. However, is there a specific best practice for firing the plugin? By the way, my firing script contains the jQuery "$". Is that an issue? Usually I would just include or add the firing script in my page template. Is there any reason not to do this?
    – jw60660
    Sep 25, 2011 at 20:03
  • The reasoning for queuing up a script is for dependencies across the entire installations. This also helps you disable other scripts programatically without having to touch plugin or WP source code. For using $, read my Good, Bad and Ugly usage of jQuery in WP. coderrr.com/jquery-in-wordpress-the-good-the-bad-the-ugly Sep 25, 2011 at 21:46
  • Thanks very much; very useful. I learned a lot about implementing jQuery in WordPress. I read your blog post. More good advice. As an additional caution, after a few hours of scratching my head (and missing a good movie w the kids!), I learned the hard way that declaring the jQuery function directly must include the capital "Q" in jQuery to work.
    – jw60660
    Sep 25, 2011 at 21:53

To add to that Brain said, you can use the enqueue_script function to add your js files to the footer if your theme uses wp_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:

                   get_bloginfo('stylesheet_directory') . '/js/myscript.js',
                   'false',  //change version #
                   'true'); //in_footer?

//here we add a priority parameter to load one before the other if needed.
add_action('wp_print_scripts', 'theme_register_scripts_other', 10);
add_action('wp_print_scripts', 'theme_register_scripts', 20);   

You can also add it to the footer using wp_footer instead of wp_print_scripts


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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