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
1 Answer
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