How to make a WordPress Child Theme

Using a WordPress child theme helps prevent any loss in changes made to a theme after it’s been updated. When you use a child theme all your customizations will be saved, even after updating the main theme.

Your child theme requires only 3 items: functions.php, style.css and a new child theme directory.

WordPress Child Theme Step 1

First you need to create a child theme directory which is located in your wp-content/theme folder. I would suggest naming it the same as your main theme, but simply add “-child” to the end of the name. If your main theme is named “main-theme”, then name your child theme directory, “main-theme-child”.

WordPress Child Theme Step 2

Second, create your child theme’s style.css file by opening a new blank sheet in your text editor or notepad. Copy and paste the stylesheet header from your main theme into your new style.css file, it will look something like this:

/*
 Theme Name:   Main Theme Child
 Theme URI:    http://example.com/main-theme
 Description:  Main Theme Child Theme
 Author:       John Doe
 Author URI:   http://example.com
 Template:     maintheme
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         tag 1, tag 2, tag 3
 Text Domain:  main-theme-child
*/

Make sure to fill it in according to your main theme.

WordPress Child Theme Step 3

Finally, create a functions.php file in your new child theme directory. Now you need to enqueue the parent theme stylesheet. Below is an example how to properly enqueue your stylesheet in your functions.php file:

<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}
?>

Wrap Up

That’s the basics of how to get your child theme going. The best place to learn more details about child themes is the WordPress Directory