Create child theme in wordpress

Create child theme in wordpress is a best way of working with Premium themes. Child theme inherit all the functionality of parent theme. Here parent theme is the theme that we bought from online or the theme that is updated frequently. We have to work with child theme in order to keep our code updated.

why we should Create child theme in wordpress

One of my friend ask me why should not we work on main theme or parent theme directly? Why should you bother to create a child theme rather than working directly in a theme ?

Well this a nice question we got. Simply say that in order to keep our customization alive just use the child theme. Whenever the theme is updated all the changes made in the parent theme is replaced by the new code sent by author of the theme. There might be various reason to do this. For security purpose they update their theme frequently. For updating functionality of woo commerc, also adding many new functionality etc..

How to Create child theme in wordpress

Creating a child theme in wordpress is a very easy. It just require a new folder inside the theme folder of your wordpress with your own website name or any other name that suit your brand. Just add a new style.css inside that folder and add a comment defining Template name, Theme name and its description with some other additional details.

Below is a basic format for what you have to do to create child theme in WordPress


/*!
 Theme Name:   Child theme
 Theme URI:    http://your-website.com/
 Description:  Yourwebsite as a child theme.
 Author:       Santosh
 Template:     Parent theme name
*/

Note: “!” mark after the comment is open, it is only required for the developer who work with SASS/COMPASS. It is just to tell the compiler that please ignore this comment and do not remove it from the output file.

Description about create child theme in wordpress

Theme Name: Child theme
It can hold any name that you can help to brand your website. For eg: Santosh Shah, Santosh kumar shah etc 🙂

Theme URI: http://your-website.com/
The url of your brand website.

Description: Yourwebsite as a child theme.
A small description to brand your website.

Author: Santosh
The name of the person who creates this child theme.

Template: Parent theme name
Very strict!!
Use the theme name for which you are going to create a child theme.

Do not forget to import the parent theme style.css in child theme.
So the whole css code to make the child theme work is below:-


/*!
 Theme Name:   Child theme
 Theme URI:    http://your-website.com/
 Description:  Yourwebsite as a child theme.
 Author:       Santosh
 Template:     Parent theme name
*/
@import "../parent-theme/style.css"

or you can use the below script to function.php


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

I hope this helps. Thanks for reading this tutorial. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *