WordPress prioritizes template files in the child theme over the parent theme. This allows child themes to override specific templates without changing the parent theme.
The wp_enqueue_scripts hook is the proper place to enqueue styles and scripts. get_stylesheet_directory_uri() returns the child theme directory URI, which is needed to load the child theme's stylesheet.
get_stylesheet_directory_uri() but notices the styles are not applied. What is the most likely cause?If the parent theme's stylesheet loads after the child theme's, it can override the child styles. The child stylesheet should be enqueued after the parent stylesheet to ensure its styles apply.
Template header in a child theme's style.css?style.css file, what does the Template header specify?The Template header in the child theme's style.css tells WordPress the folder name of the parent theme. This links the child theme to its parent.
functions.php code in a child theme. What will be the output when the site loads?add_action('wp_enqueue_scripts', function() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css');
wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css', ['parent-style']);
});
add_action('wp_head', function() {
echo '<!-- Child theme loaded -->';
});add_action('wp_enqueue_scripts', function() { wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css'); wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css', ['parent-style']); }); add_action('wp_head', function() { echo '<!-- Child theme loaded -->'; });
The code enqueues the parent stylesheet first, then the child stylesheet with the parent as a dependency, ensuring correct load order. The comment is echoed in the head section, so it appears in the page source.