This works:
add_action('wp_enqueue_scripts', 'custom_script_enqueue');
function custom_script_enqueue() {
wp_enqueue_style(
'customstyle',
get_template_directory_uri() . '/css/theme.css',
array(),
'0.1',
'all'
);
wp_enqueue_script(
'customjs',
get_template_directory_uri() . '/js/js.js',
array(),
'0.1',
true
);
}
But my custom JS is going to use a couple of jQuery calls. It's currently failing because jQuery is loaded after this custom script and so jQuery is coming back as being undefined on page load.
I read some answers here and tried this:
add_action('wp_enqueue_scripts', 'custom_script_enqueue');
function custom_script_enqueue() {
wp_enqueue_style(
'customstyle',
get_template_directory_uri() . '/css/theme.css',
array(),
'0.1',
'all'
);
wp_enqueue_script(
'customjs',
get_template_directory_uri() . '/js/js.js',
array('jQuery'),
'0.1',
true
);
}
Now, my custom script doesn't load at all. It's nowhere to be found when I view-source: on the page.
I tried replacing wp_enqueue_script with wp_register_script and then calling wp_enqueue_script('customjs'); below, but although it throws no errors, I get the same (lack of) result.
get_template_directory_uri();for readability.get_template_directory_uri();in the code. Use concatenation if it will help with readability. Not everyone reads the comments and there's a big difference between usingget_template_directory_uri()and not, in this case.jquery(all lowercase).