<?php
function load_my_styles() {
wp_enqueue_style('my-style', get_template_directory_uri() . '/css/style.css');
}
add_action('wp_enqueue_scripts', 'load_my_styles');
?>The wp_enqueue_scripts hook is the right place to enqueue styles and scripts for the front end. The function uses get_template_directory_uri() to get the theme folder URL and appends the path to the CSS file. This causes the style to load in the page header.
The third parameter of wp_enqueue_script is an array of dependencies. To depend on jQuery, you must pass array('jquery'). The last parameter true loads the script in the footer. Option B uses both correctly.
<?php
function load_scripts() {
wp_enqueue_script('main-js', get_template_directory_uri() . '/js/main.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'load_scripts');
?>The wp_enqueue_script call is missing a closing parenthesis at the end of the line, causing a PHP syntax error and fatal error on load.
<?php
function load_scripts() {
wp_enqueue_script('script-one', get_template_directory_uri() . '/js/one.js', array(), null, true);
wp_enqueue_script('script-two', get_template_directory_uri() . '/js/two.js', array('script-one'), null, true);
wp_enqueue_script('script-three', get_template_directory_uri() . '/js/three.js', array('script-two'), null, true);
}
add_action('wp_enqueue_scripts', 'load_scripts');
?>Each script depends on the previous one, so WordPress loads them in dependency order: one.js first, then two.js, then three.js. All load in the footer because of the last argument true.