How to Create Child Theme in WordPress Step by Step

How to Create Child Theme in WordPress Step by Step

 Do you want to create a child theme? If you are learning WordPress Basic. You need to learn a child theme. In this article you will learn How to Create Child Themes in WordPress Step by Step.

Lots of premium and free themes are available. But we need to customize with our own interest. Each website needs its own specific designing. You can customize your parent theme design with a child theme. Do you know what child themes are?

What is WordPress Child Theme:

Child themes are themes that can change parent theme functionality and specific template. If you want to understand child themes. You need to understand Parent theme.

Parent Theme: The parent theme is a complete theme. Which have all of the required WordPress template files and assets. It’s a completely independent and working theme.

Child Theme: The child theme depends on another complete theme. This is not a complete theme. This theme is only for some change in template and functionality.

But with the child themes, You can fully change parent theme design. Also, can add any functionality.  

Why use Child Theme:

Think about a popular WordPress theme that theme use in lots of websites. All of the website designs are not the same. You can change the parent theme template but when the theme update comes that change vanishes. For permanent change you need to use a child theme.

Modern themes have so many options to change templates. But options increase difficulty. Also, Increase HTTP requests. Other hand, You can use plugins but for the simple change you don’t need to use plugins.

Like, You want to add a portfolio. You can do it with a plugin. But if you write simple code in your child theme. You can make a portfolio easily. How to Create a Portfolio Gallery in WordPress.

Different people have different interests. Each webmaster wants his blog or website customized with different ideas. That is why you need to use a child theme.

Child Theme Required File: 

A child theme’s first job is to overwrite parent theme files. But there are some files like style.css and functions.php that do not overwrite. Otherwise, any template file can be overwritten. 

So, In case we can decide style.css is only the required file for the child themes. If you want to add functionality or assets you need to create a file named functions.php. Let’s create a child theme.

How to create WordPress Child Theme:

It’s easy to create a child theme. We can get child theme template locations using the get_stylesheet_directory() function and for asset URL using get_stylesheet_directory_uri() function.  Just follow the step:

  1. Create a folder in the WordPress Themes directory. Go to wp-content > themes >Your child theme names. 
  2.  Then create a stylesheet file. Create style.css file under child theme folder.
  3. Create WordPress theme info on child theme header comments. Like,

Use this code on your stylesheet file:

/*
 Theme Name:   Twenty Twenty One Child
 Theme URI:    http://wpknifer.com/
 Description:  Twenty Twenty One Child Theme
 Author:       John Doe
 Author URI:   http://wpknifer.com
 Template:     twentytwentyone
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twentytwentyonechild
*/

Remember, Replace the Theme name and other information with your own. Must replace Template: Your parent theme text-domain.  

  1. Your child theme is already created but the parent theme stylesheet does not load in the child theme. In case we need to create functions.php load stylesheet file with wp_enqueue_scripts. Like:
<?php 
add_action( 'wp_enqueue_scripts', 'twentytwentyone_child_enqueue_styles' );
function twentytwentyone_child_enqueue_styles(){

	wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css'); 
	wp_enqueue_style( 'child-style', get_stylesheet_uri(), array(), '1.0.1');
	
} 

That’s it the child theme was created fully. You can add additional CSS on style.css. And you can add custom functions. Also, you can Customize template files. In the next section, we will show how to customize Template files.

Customize Theme Template in Child Theme:

You can customize the theme template in the child theme.  Parent theme template can be overwritten in the child theme. But you need to know what WordPress template Hierarchy. We make common WordPress theme template file list:

Index.php: This is the root template file for the WordPress theme. When no templates are found the output will come with index.php.

Front-page.php: This template for home page display. You can overwrite the home page.

Page.php: This template for single page or usual page overwrite.

Privacy-policy.php: This template can be displayed for the Privacy-policy page.

Single.php: This template for single post or custom post type single post display.

Category.php: This template for category page display.

Archive.php: This template for custom post type archive page display.

Search.php: Use for this template search page display.

404.php: This template for error page display.

Header.php: You can overwrite the header.

Footer.php: You can overwrite the footer.

Sidebar.php: You can override the sidebar.

Also, All templates you can overwrite. Which uses the get_template_part() function for including templates. Firstly you need to check the parent theme directory. And copy the template file and place them in the same location. Then you can edit them. 

If you want those temple files which do not exist in your parent theme. That time you have full freedom to customize that template.  

Conclusion: 

It’s so easy to customize a theme using a child theme. But You need to understand first. You can change everything’s using a child theme. When the theme update comes. It does not affect the child theme. We think you already know How to Create a Child Theme in WordPress Step by Step.

We hope this article will help you. If you face any problem with creating a child theme. Please Comment below.

See More:

Create a Portfolio Gallery in WordPress

How to create popular post widgets without plugin in WordPress

How to get the next and previous post link in WordPress

Leave a Reply

Your email address will not be published.