Creating a Child Theme in WordPress

When you are working with theme customization in WordPress, it is a good idea to create a child theme of the theme you want to start with. A child theme will look and feel like its parent theme, but will allow changes that you make to be retained when the parent theme is updated.

The first step to creating a child theme is to navigate to your themes directory located at /wp-content/themes. Once there, create a new directory for your child theme. You can call it whatever you want, but it is common to name it after the parent theme and append -child to the directory name.

Once your directory is created, you need to create a stylesheet in the directory and name it style.css. This stylesheet should contain the header comment below at the top of the file:

/*
 Theme Name:   Twenty Nineteen Child
 Theme URI:    http://example.com/twenty-nineteen-child/
 Description:  Twenty Nineteen Child Theme
 Author:       Your Name
 Author URI:   http://example.com
 Template:     twentynineteen
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags: one-column, flexible-header, accessibility-ready, custom 
 colors, custom-menu,   custom-logo, editor-style, featured-images,         
 footer-widgets, rtl-language-support, sticky-post, threaded- 
 comments, translation-ready
 Text Domain:  twentynineteenchild
*/

It’s important that the Template matches the directory name of your parent theme. Other things to watch out for are to make sure that you use the correct theme tags. Allowable theme tags are specified by WordPress.

The style.css theme is the only file that is required for the child theme, but you will need to add a functions.php file in order to enqueue styles correctly. The contents of that file should look something like this:

<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
 
    $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
 
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
}

Once those files are in place you can activate your child theme in your sites Administration Screen.

Using a Child Theme

Once your child theme is in place, you can copy over any template files you want to modify and make the changes within your child theme directory where they won’t be affected by updates to the parent. Additionally you can add CSS and PHP functions to the style.css file and functions.php within your child theme.