What is a Child Theme?

A child theme in WordPress is a child theme for the original theme with all its Functionality, Component, Features, Stylesheet, and more.

Why Child Theme?

If we need to make any changes in files like CSS, Php files and we make changes on the parent theme, so when the theme is updated all these changes will be lost. so here the child theme comes, we create a child theme and make changes to it.

How to create a child theme?

Step 1

– Create a new folder in theme director at wp-admin/themes. The name of the folder is related to your parent theme so if your parent theme is like ( twentynineteen) then your child theme is ( twentynineteen-child ).

– Now we need to add some files in our child theme folder like: style.css and function.php. These 2 files are compulsory to create in child theme.

Step 2

– Create a file and rename it as style.css. and add the below content as a comment as shown below

/*  
	Theme Name:   Twenty Nineteen Child  
	Theme URI:    http://example.com/twenty-nineteen-child/  
	Description:  Twenty Nineteen Child Theme  
	Author:       John Doe  
	Author URI:   http://example.com  
	Template:     twentynineteen  
	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:  twentynineteenchild 
*/ 

In the above code these are the required to add in code:

  1. Theme name is for unique child theme name.
  2. Template is the name of the parent theme directory name like your parent theme folder name is ( twentynineteen ) then Template is twentynineteen

Step 3

– Create a file and rename it as functions.php. this file is used to add your parent theme CSS to your child theme and also creating new functions you need for your website. the below code is for enqueuing the parent theme stylesheet.

<?php
	add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
	function my_theme_enqueue_styles() {
		wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
	}

When you add this code in your functions.php file it will call all CSS of your parent theme into your child theme.

Step 4

Activate your child theme From your Admin Dashboard and now Your child theme is exactly like the parent theme and you can add CSS to your child theme. If you need to edit something like in the header.php file, you just need to copy the header.php file from your parent theme and paste it into child theme make changes what you need to do. same for the other files like footer.php etc.

That’s it. now your child theme is complete.