Complete the code to declare a child theme's style.css header.
/*
Theme Name: My Child Theme
Template: [1]
*/The Template field must match the parent theme folder name exactly. Here, 'twentytwentytwo' is the parent theme.
Complete the code to enqueue the parent theme stylesheet in the child theme's functions.php.
<?php
function child_theme_enqueue_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri() . '/[1]');
}
add_action('wp_enqueue_scripts', 'child_theme_enqueue_styles');The parent theme's main stylesheet is usually style.css. This code loads it properly.
Fix the error in the child theme's functions.php to properly enqueue styles.
<?php
function child_enqueue() {
wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css', array([1]));
}
add_action('wp_enqueue_scripts', 'child_enqueue');The child style should depend on the parent style handle, which is 'parent-style' in this example.
Fill both blanks to override a parent theme template file in the child theme.
<?php // To override the parent theme's [1] file, // copy it to the child theme folder and modify [2].
To override single.php, copy single.php from the parent theme to the child theme and edit it there.
Fill all three blanks to properly enqueue child and parent styles with versioning.
<?php
function enqueue_styles() {
$parent_version = wp_get_theme()->get('Version');
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css', array(), [1]);
wp_enqueue_style('child-style', get_stylesheet_directory_uri() . '/style.css', array([2]), wp_get_theme()->get('Version'));
}
add_action('[3]', 'enqueue_styles');Use false for no version on parent style, set child style dependency to 'parent-style', and hook into 'wp_enqueue_scripts'.