If you’ve purchased a premium WordPress theme that didn’t happen to have a child theme included, this tutorial will show you how to create a child theme before you start building out your new site.

 

 

Let’s dive right in

To get started, open your text editor or IDE of choice and open your WordPress site root directory, whether it is a local install or already on a server. From your WordPress root directory navigate to /wp-content/themes/ and create a new directory with whatever name you like. A lot of themes use the “parent_theme_name_here-child” naming convention, so you can use that if you can’t think of something. I’m going to name my child theme “cool-theme”.

In the cool-theme directory, create a new file named style.css and add the following code:


/*
 Theme Name:   Cool Theme
 Theme URI:    https://coolsite.com
 Description:  Child theme of parent_theme_directory_name_here
 Author:       Dustin Parker
 Author URI:   https://dustinparkerwebdev.com
 Template:     parent_theme_directory_name_here
 Version:      1.0.0
 Text Domain:  cool_theme
*/

Note that the only two parameters that are required are Theme Name and Template. Without those, your child theme won’t work.

Next, create a new file in the cool-theme directory and name it functions.php. Inside functions.php, add the following code after the opening <?php tag:


add_action('wp_enqueue_scripts', 'cool_theme_enqueue_styles');
function cool_theme_enqueue_styles() { 
    wp_enqueue_style('parent-styles', get_template_directory_uri().'/style.css');
    wp_enqueue_style('cool-theme-styles', get_stylesheet_directory_uri().'/style.css', array('parent-styles'), '1.0.0');
}

Now just login to your WordPress admin and make sure both parent and child theme show up under Appearance > themes, activate your child theme, and begin customizing. For more information on overriding parent theme templates, loading scripts and styles, and more, see the official WordPress Child Theme handbook.


Dustin Parker

Dustin is a web developer with a passion for building custom websites and web applications on platforms/frameworks such as WordPress, Shopify and Laravel.