What is a Child Theme?

A Child theme in a 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 file and we make changes on parent theme, so when the theme updated all these change will lost. so here the child theme comes, we create a child theme and make changes on it.

How to create a child theme?

Step 1

– Create a new folder in theme director at wp-admin/themes. 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 below content as 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 as functions.php. this file is used to add you 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.

	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 in to your child theme.

Step 4

Activate your child theme From your Admin Dashboard and now Your child theme is exactly like parent theme and you can add css to your child theme. If you need to edit something like in header.php file, you just need to copy header.php file from your parent theme and paste it in 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.