Featured image for the post Building A Child Theme

Building A Child Theme

Unless your WordPress theme was developed specifically for your own use you should always be using a child theme. The reason for this is obvious, if you don’t use a child theme and you make customisation changes, all these changes will be wiped out the next time the parent theme author makes a new version of his/her theme available.

The theme that I am running here is a child theme of one of my other themes. In trying to show you how to build a child theme I am simply going to provide the code I used to get this child theme up and running.

Firstly you need to create a new directory under /wp-content/themes/name-of-your-child-theme/. In this directory you need two files, style.css and functions.php.

In style.css you need the following code:

 Theme Name:   Name of your child theme.
 Description:  A description of your child theme.
 Author:       Your name.
 Author URI:   Your URL.
 Template:     Name of the parent theme.
 Version:      Version of your child theme.
 Tags:         Tags you require.
 Text Domain:  Text domain for the child theme.

Not much code here but you need to do things correctly or the sky will fall on your head. The theme name should be something short and simple. If you are planning to add your child theme to the WordPress Theme repository and you are not the author of the parent theme you are using you cannot use the name of the parent in the name of your child. The theme reviewers will not allow this.

The description is anything you require to describe your child theme.

The author is simply your own name and the author URI is the URI of your own site The description, author, author URI are all optional.

Next is the template, this is the most important part here. This is the slug used by the parent theme. Let’s say you are making a child for my own theme amaThambo. The slug I use for this theme is amathambo, this is what you will add here.

You can add a version for your child theme as well as any tags you might need. These tags are normally simply the tags used by the relevant parent theme.

The last item is also pretty important. Let’s say I called my child theme amaThambo Child the text domain I would use is amathambo-child.

Below all this stuff you have just added is where you will add all the styling changes you require in your child theme.

Okay, let’s get to our second file we added, functions.php. In this file you need the following code:

 * Enqueuing the stylesheet for the child theme
 * @package WordPress
 * @subpackage Name of your child
 * @version the version you used in the stylesheet
function your_text_domain_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
add_action( 'wp_enqueue_scripts', 'your_text_domain_enqueue_styles' );

This code simply enqueues the correct stylesheets needed to make everything work. It is in this file that you will add all your functions you might need to make your child different from the parent theme.

That’s it, that’s all it takes. All you need do now is to ensure that you have the relevant parent theme loaded in your WordPress installation but you do not activate this parent, you activate the child theme you have just created.

Now you can customise your child theme to your hearts content in safety. All changes in future versions of the parent theme can no longer wipe out all your hard work. Happy customisation.

One thought on “Building A Child Theme

Start or Join the Conversation

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.