Personal Blog

How do I create a child theme in WordPress?

If you want to modify your WordPress theme, the best way to do it is to create a child theme. The child theme will simply import the parent theme and apply any changes you have made within the child.

This means that the WordPress core files and the parent theme can be updated without overwriting any changes you have made yourself.

The child theme is a theme in its own right. It will need to be placed in the same “wp-content/themes” directory as all other themes on your installation. The child theme will also need to be activated via the WordPress admin panel.

You may add template files from the parent theme, to the child theme and modify them accordingly.

To create a child theme

You will need to create a new style.css file in your child theme directory. The child theme will work with just this one file but it must me there.

First, create a folder and name it “child” or whatever you want to call it.

With your favorite plain text editor (notepad etc.) create a file and name it style.css. If you are lazy (like me) you could just copy your style.css file from the parent theme and delete the entire content. You will then need to insert in to it the following text:

Theme Name: name-of-child-theme
Theme URI: not important
Description: Child theme for my parent theme
Author: That’s you
Author URI: not important
Template: name-of-parent-theme
@import url("../name-of-parent-theme/style.css");

Any changes you wish to make to the parent theme’s style.css you may add below the last line.

The easiest way to manage your child theme is to just add css elements from the parent theme’s style sheet that you wish to make changes to and copy from the parent theme the template files that you wish to modify. If you make any mistakes or cause the theme to generate errors, you can just copy over a new template file and start over.