Child Themes and its usage

In this blog post i am going to tell you about Child Themes and its usage. Template Sell have more than 4 premium themes and more than 8 free WordPress Themes up to today date. Some of our vendors got approved and some of them are under the review. With few days, you will get more WordPress Themes from different vendors.

In this blog post, today I am going to share you about the child theme, how we can make it and its usage as well. If you are using any free or premium theme and you want to customize it, Child Theme is highly recommended in that case. Some of the premium theme comes with child theme and some need to create yourself. Creating child theme is not so huge task, it’s simple, just follow this post completely. After that you can create your own child theme within few minutes.

What is Child Theme?

A child theme is a theme that inherits the functionality and styling of its parent theme. Child themes are the recommended way of modifying an existing theme without losing the ability to upgrade that theme. Child Theme are highly recommended to modify the existing theme i.e. parent theme. For example: If you are using theme name called, Penman and if you want to modify its design and want to add/remove some features, child theme is recommended. You can edit the parent theme codes, but if your parent theme code is edited, means added or removed, after the theme updates, your all changes will lost. So, never edit the parent theme code directly. Use Child Theme in such case. If all the changes are made from the child theme, you can upgrade the parent theme and it will not affect the changes on the site. Your changes will remain safe.

Customize Parent Theme via Child Theme

If you want to change the design or functionality of the parent theme, you can use the child theme. If you have child theme already on your theme package, upload both the theme on Appearance > Themes and activate the child theme. Your child theme must be activated to see the changes via child theme.

If your theme package doesn’t have the child theme, you can create child theme with the help of Plugin or you can create it manually.

Create your own Child Theme

If you want to create your own child theme, you can find the various plugins on WordPress repository to create Child Themes. You can use any one of the available plugin to create child theme. Here, I am going to show you about how to create child theme manually.

First you need to confirm the Parent Theme of which you are going to create a Child Theme. Here I decided to create a Child Theme of WordPress default theme Twenty Seventeen. Two necessary file to create child theme are style.css and functions.php .

  1. Create a directory of child theme. Directory name must be parent theme name – and child theme name. In this case, directory name must be twentyseventeen-child. Here parent theme directory name is twentyseventeen.
  2. Now create a file style.css inside that directory and paste the below codes on style.css file.
 /*

Theme Name:   Twenty Seventeen Child

Theme URI:    http://example.com/twenty-seventeen-child/

Description:  Twenty Seventeen Child Theme

Author:       Your Name

Author URI:   http://example.com

Template:     twentyseventeen

Version:      1.0.0

License:      GNU General Public License v2 or later

License URI:  http://www.gnu.org/licenses/gpl-2.0.html

Tags:         blog, two-columns, right-sidebar, responsive-layout, accessibility-ready

Text Domain:  twenty-seventeen-child

*/

Important things to take care about: The Template line corresponds to the directory name of the parent theme. The parent theme in our example is the Twenty Seventeen theme, so the Template will be twentyseventeen. You may be working with a different theme, so adjust accordingly. Template is the directory name of parent theme. If you are going to make the child theme of Penman, you need to write the penman on template.

  1. Now, it’s time to create functions.php file. Create another file named functions.php and paste the below code on that file.
 <?php

function my_theme_enqueue_styles() {

 

$parent_style = 'parent-style'; // This is 'twentyseventeen-style' for the Twenty Seventeen theme.

 

wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );

wp_enqueue_style( 'child-style',

get_stylesheet_directory_uri() . '/style.css',

array( $parent_style )

);

}

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );

?>
  1. Your child theme is now ready. Make the zip file of that child theme directory and upload the child theme on Appearance > Themes > Add New > Upload and upload the zip file and activate that theme. Make sure, parent theme is in the directory, otherwise your child theme will not functional.

How to override the parent theme via child theme?

If you want to customize the parent theme via child theme, kindly follow the below steps:

  1. Create a child theme. You can make your own child theme with the help of above listed methods.
  2. Make the same directory path on the child theme as parent theme have. If you want to customize the file of `template-parts/content.php`, you need to make the same path on child theme. `template-parts/content.php` and you can edit the child theme codes. Only copy the files on child theme. You are not allowed to remove that file from parent theme, otherwise your theme is incomplete.
  3. If you need to edit other files, you can follow the same process above.

I think, this blog post is very helpful for you to make your own child theme, to understand the child theme as well as how to override the parent theme via child theme.

Written by