How To Create Child Themes For WordPress

Are you not satisfied with your current theme? Do you want to customize it according to your needs?

The best way to do so is by creating a child theme and then customizing it as per your liking.

Why creating child themes is important

You might be wondering why create a child theme and not customize the parent theme itself. Editing the parent theme should always be avoided. There are many reasons for this. The biggest one being if you end up messing the themes code you will have a parent theme to revert back to.

Having a child theme is also a great way to keep track of all the changes you have made in your theme. Also, if you use the parent theme for customizing and the theme gets an update. All your changes will be overridden.

Steps to create a child theme

The first step will be to create a folder in /wp-content/themes/. You can name it anything you want, we will be naming it twentynineteen-child. Since we are creating a child theme for the twentynineteen theme for this article. So your name for the folder would be yourthemename-child.

In the twentynineteen-child folder create a file called style.css. Inside this file paste the below code.

/*

Theme Name:   Twenty Nineteen Child Theme

Theme URI:    https://www.website.com/

Description:  A Twenty Nineteen child theme

Author:       Self

Author URI:   https://www.website.com

Template:     twentynineteen

Version:      1.0.0

*/

@import url("../twentynineteen/style.css");

You can now save the file.

The part that tells WordPress that this is a child theme is the Template code where we mentioned twentynineteen as the parent theme. You will replace twentynineteen with your parent theme name, so it becomes:

Template:     yourparentthemename

The next step is to activate the theme. Visit Appearance -> Themes from your admin dashboard. You will now see the Twenty Nineteen Child Theme in the themes section. Click on the Activate button.

Your website’s design will be the same as before as no changes have been made yet.

Editing your child theme

For editing the theme now all you have to do is copy the classname or id of that div and start adding styles below the @import statement in the style.css file.

For example if you want to change the background of widgets then copy it’s classname i.e., widget. So the code would be

.widget{

background-color: #colorcode;

}

Editing the template Files

Many times you will also want to change the layout with the stylesheet. Let’s say you want to remove the powered by WordPress text from the footer. Simply copy the footer.php file from the parent theme and place it in the twentynineteen-child folder. Now you just have to remove the text you don’t want from the layout and save the file.

Bottom Line

If you are going to edit your theme then it is important that it is done within a child theme. Child themes are a useful feature provided by WordPress that makes it very easy to edit your theme. A child theme is a fail-safe method using which you can never go wrong.

Have questions or confused about something WordPress Related? Join Our Forum & ask a Question

Leave a Comment

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

Scroll to Top