I’m trying to load jQuery and other scripts into the header (or should it be footer), and I have the jQuery working sort of I can get an alert box running.
The thing is, jquery-2.0.3.min.js
isn’t loading, and I don’t know if I’m doing the enqueue correctly. jquery-1.10.2 is loaded though. And also, the other script isn’t loading either. For both scripts (2.0.3 and other script), this is at the end: ?ver=3.6.1
Also I was reading that it might be better load both into one function?
So, any help would be appreciated!
function load_jquery() {
wp_register_script( 'jquery_script', get_template_directory_uri() . 'js/jquery-2.0.3.min.js', array( 'jquery' ) );
wp_enqueue_script( 'jquery_script' );
}
add_action( 'init', 'load_jquery' ); // end jQuery
function another() {
wp_register_script( 'another_script', get_template_directory_uri() . 'js/another.js', array( 'jquery' ) );
wp_enqueue_script( 'another_script' );
}
add_action( 'init', 'another' );
First thing jquery in there by default in wordpress so you dont have to register it , just enqueue it
most of the jquery ui libs and core jquery files are already registered with wordpress so you only need to enqueue with right handle look here enqueue script
wp_enqueue_script
is used to enqueue script andwp_enqueue_style
is used to enqueue stylefor calling custom js, its better to register script or style first before using
wp_register_script
// to register scriptwp_register_style
// To register stylethen enqueue using
wp_enqueue_script
,wp_enqueue_style
here is a sample code snippet for whole process from my site
also remember to hook your function with
wp_enqueue_scripts
so that scripts & style load correctlyadd_action( 'wp_enqueue_scripts', 'pr_scripts_styles' );
This works for me when using child theme, just be sure to use different names for the scripts:
This is how i add styles and scripts works great for me.
But i suggest before using it understand it first and then anyone can follow this approach there own way.