WordPress

How to Create a WordPress Child Theme

If you love your current theme but want to modify its features and look, child themes are considered the best way to customize your WordPress themes. A child theme inherits all the features and appearance of its parent theme. You can customize it without affecting the parent theme. This allows you to easily update parent theme without worrying about losing your changes.

What is Child Theme?

Since a child theme inherits the characteristics of a master or a parent theme, you can customize its code without breaking the original’s functionality. This way, if a theme gets an update, all of the changes you made won’t be overwritten.

Why You Should Be Using Child Themes?

Using WordPress child themes to modify the theme is one of the safest and recommended way. Your changes will not be deleted if your parent theme gets updated. Another benefit of using child theme is if your child theme modification creates issue you can always deactivate the child and revert back to parent theme.

Creating a Child Theme in WordPress

The following instructions use Twenty Twenty as the base. You can use another theme if you prefer. First you need to open /wp-content/themes/ in your WordPress installation folder and create a new folder for your child theme. You can name this folder anything you want. For this tutorial we will be naming it my-child-theme.

I do not recommend you to make any folder in your live server, you can make child theme folder on your PC and then after completion of child theme we can directly upload it to WordPress admin panel just like normal theme upload.

 

 

In “my-child-theme” folder create a text file using Notepad or any other text editor (Notepad++) and paste this code:

/*
Theme Name: My Child Theme
Description: This is my child theme
Author: Indrapal Kushwaha
Author URI: https://woochamp.com
Template: twentytwenty
Version: 1.0.0
*/

// Custom styles go here

As shown in below image

 

 

Now save this file as style.css in the ch”my-child-theme” folder you just created.

 

 

Now you will find a new file called “style.css” & now you can delete “New Text Document” text file which we create earlier.

Note: Do not delete “style.css”file

Most of that stuff in this file is self explanatory. What you really want to pay attention to is the Template: twentytwenty.

This tells WordPress that our theme is a child theme and that our parent theme directory name is twentytwenty. The parent theme folder name is case-sensitive. So you need write same name in front of Template in style.css file which which we have created in above step. If we provide WordPress with Template: TwentyTwenty, then it will not work.

TIP: you can check folder name in your server file manger (../wp-content/themes)

 

 

Create a function.php file

Create another file named functions.php in the same folder “my-child-theme” , but do not fill it with the code from the parent theme’s file because it needs to remain separate. Instead, copy and paste the code below to the blank file and save it:

Note: You need to another software called “Notepad++” to create function.php file as normal text editor (Notepad) will not work here.

<?php

add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );

function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}

//* Code goes here

 

 

Now you will see two files here after creating function.php file

 

 

All Done! Now its time to create a theme thumbnail image

Create Child Theme Thumbnail

We need to create Child Theme thumbnail image to show it in WordPress admin panel something like this (refer below image). Remember you need crate this thumbnail image in dimension of  880×660 and should be “screenshot.png” of theme thumbnail.

 

 

Here is the Child Theme thumbnail image.

 

 

Now its time to zip the “my-child-theme” folder and upload it to WordPress admin panel. Right click on folder and select 7-zip (if you do not have this software the install it in your PC), choose Add to “my-child-theme.zip” option to zip your my child theme folder.

 

 

You can refer below image

 

Upload and Activate Your Child Theme to WordPress admin panel

Now its time to upload your child theme (zip file) to your WordPress admin panel, go to your website admin panel and select Appearance>Theme and then click on Add New button on the top, again click on Upload Theme button. Now click on Choose File to upload your theme in WordPress theme section.

 

Click on Install Now button and if everything is perfect then it will ask for activation of the child theme, just click on activate button.

 

 

You’re Awesome!! you have created your first child theme. Click here to download your child theme (change the template name) and you are good to go.