Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am pretty new in WordPress and I have the following doubt: I have to include JQuery into a theme and I am doing in this way:

I create the following function into functions.php theme file and I add it as action:

function load_java_scripts() {
    // Load FlexSlider JavaScript that handle the SlideShow:
    wp_enqueue_script('jQuery-js', 'http://code.jquery.com/jquery.js', array(), '1.0', true);
}
add_action('wp_enqueue_scripts', 'load_java_scripts');

So I think that I can add it as some other javascript or CSS local resources but I am not sure about this method because in this case the jquery.js is not a local resource but is an online resource (is the same thing?)

And I also have some doubts because searching online I have found some differents method to add JQuery to my theme, like this one: http://css-tricks.com/snippets/wordpress/include-jquery-in-wordpress-theme/

Can you give me some more precise information about how to correctly complete this task?

Tnx

Andrea

share|improve this question
    
Why are you including an external copy of jquery? Is the included jquery library in WordPress not suitable for your uses? –  t31os Jan 21 at 19:08

1 Answer 1

When you register/enqueue your other scripts, simply pass jQuery as the third parameter and it will be loaded first and only once, from the local WordPress files:

wp_register_script( 'theme-js', get_template_directory_uri() . '/js/theme.js', array( 'jquery') );

If you only need the jQuery, simply use:

wp_enqueue_script('jquery');

You can find a list here about the javascript libraries that are included in your default WordPress site:

http://codex.wordpress.org/Function_Reference/wp_enqueue_script#Default_Scripts_Included_and_Registered_by_WordPress

share|improve this answer
    
mmm are you meaning that WP automatically load JQuery in some way and that I have not to manually load it but that I can only pass it as dependency of the other JavaScript that require it? –  AndreaNobili Jan 21 at 11:41
3  
I mean jQuery is in WordPress by default, located in the wp-includes folder, so you don't need to use an external source to include the javascript file. You can find all of the libraries included in WordPress in the codex, i updated my answer with a link. Also worth to mention, that jQuery is in no-conflict mode, so instead of $(document).ready(function(){... you should start with jQuery(document).ready(function($){... –  passatgt Jan 21 at 11:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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