Categories: Wordpress

Creating Child Theme for WordPress

What is a Child Theme?

A child theme for 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 child theme in wordpress step by step?

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.

Anil Kumar

Published by
Anil Kumar

Recent Posts

Best Ways to Create or Convert Images to Ghibli-Style.

Studio Ghibli is famous for its beautiful, hand-painted animation style with soft colors, dreamy landscapes,…

5 months ago

Top 10 WordPress Benefits Compared to Other CMS Platforms

When creating a website, choosing the right Content Management System (CMS) is crucial. There are…

5 months ago

10 Must-Have Essential WordPress Plugins for a Simple Website

If you’re building a WordPress website, you’ll need plugins to add important features like contact…

6 months ago

How to Select the Best WordPress Theme for Your Site

Selecting a best WordPress theme may be a small detail, but it has a big…

6 months ago

How to Secure Your WordPress Website from Hackers

WordPress is one of the most popular content management systems (CMS) in the world, but…

6 months ago

WordPress Speed Optimization for Better Performance

WordPress speed optimization is one of the most important factors in user experience and SEO.…

6 months ago