Create a WordPress Child Theme

  1. Create a new folder inside your theme directory.
    • Naming the usual practice when creating a child theme is to give its folder the same name as the parent theme appended with -child. That way, anyone knows immediately that this is the child of an existing theme.
  2. Create the new style sheet.
    • This is the file that contains your theme’s CSS code and configuration for your theme’s design.
  3. Add style sheet header which contains important information about your child theme.
    1. Link to WordPress docs with a child theme template: https://developer.wordpress.org/themes/advanced-topics/child-themes/
  4. Here’s a slimmed down version:
/*
Theme Name: Twenty Twenty-One Child
Description: A child theme of the Twenty Twenty-One default WordPress theme
Author: Brian Bellino
Template: twentytwentyone
Version: 1.0.0
*/

Enqueue stylesheet

  1. Create functions.php
  2. For version Twenty Twenty-One add the follow code:
<?php

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    $parenthandle = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
    $theme = wp_get_theme();
    wp_enqueue_style( $parenthandle, get_template_directory_uri() . '/style.css', 
        array(),  // if the parent theme code has a dependency, copy it to here
        $theme->parent()->get('Version')
    );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(),
        array( $parenthandle ),
        $theme->get('Version') // this only works if you have Version in the style header
    );
}

Additional Resources