Skip to content

Creating a Child Theme in WordPress

Published:  at 12:00 AM

A child theme allows you to extend the styles and functionality of a WordPress theme without losing them with every update of the parent theme.

  1. Create a directory inside wp-content/themes with the same name as the parent theme and the suffix -child. For example: twentytwenty-child.

  2. Create a style.css file with the code:

    /*
    Theme Name:   Twenty Twenty Child
    Template:     twentytwenty
    */

    The only required fields are Theme Name and Template, where Template is the name of the parent theme’s directory.

  3. If you want to load the parent theme’s stylesheet as well (most likely yes), you must also add a functions.php file in the same directory with the code:

    <?php
    /* enqueue script for parent theme stylesheet */
    function childtheme_parent_styles() {
      // enqueue style
      wp_enqueue_style( 'parent', get_template_directory_uri().'/style.css' );
    }
    add_action( 'wp_enqueue_scripts', 'childtheme_parent_styles');

Finally, you can activate the theme from the Appearance section of the WordPress dashboard.