Child theme and its benefits

What is Child theme

A child theme is a theme that inherits all styles and functions from another WordPress theme, the parent theme. You can simply create a child theme which mostly consists of  two files, the first file is style.css file which contains the reference of the parent theme style.css file and the second file is functions.php file which can help you in overriding the functions of the parent theme.

Benefits of using Child theme

There are many people who get confused when they are customizing or tweaking their theme and they fear from customization being lost if they will update the theme to its latest version in the future. Many people prefer to build their websites using the WordPress so WordPress have given a smart solution to this problem as well which is to build a child theme.

1.  Safe Theme Update

The biggest advantage which child theme gives you is that your customization is not lost during the theme update since your all customization resides inside your child theme so you can easily update your theme without any hesitation.

2.  Easily Extend Parent Theme

You can easily extend the parent theme functionality by adding files such as parent theme template files in your child theme and can override them according to your requirements.

3 . Fallback is Safe

When you are extending or customizing the parent theme then there occasions when you have forgotten to write code for something, in that case there is always the parent theme’s functionality available as the fallback option.

Steps for creating Child theme

1. The first thing you need to do is to create a new folder for your child theme (example: “ crystal-child”) under the wp-content/themes folder.

2. The second step is inside the child theme folder, create a CSS file with the name  style.css. The stylesheet must begin with the following (the stylesheet header).

/*
Theme Name: Crystal Child Theme 
URI: https://crystal.code125.com/
Author: Code125 
Author URI: https://code125.com/ 
Template: crystal
 Description: Any description you can write about your child theme.
 */ 

@import url("../crystal/style.css");
/* Theme customization starts here -------------------------------------------------------------- */
  • Theme Name (required) = use the parent theme name + child to make it easy to identify (example “Crystal Child”).
  • Theme URI (optional) = your theme link.
  • Author (optional) = your name.
  • Author URI (optional) = your website link.
  • Template (required) = name of the parent theme folder (in this case, it is “crystal”).
  • Description (optional) = you may enter any text here.

3. The third step is to create another file with name  functions.php file. Edit the new file using any editor such as Notepad++, and place the following code on the top of it.

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

4. The fourth step is to add a screenshot which resides inside your parent theme folder, you can simply copy the screenshot and add to your child theme folder and then finally zip the child theme folder.

How to activate the Child theme

The way to activate a child theme is exactly the same as for any other theme. Log in to your website’s admin panel and go to your website admin  Dashboard > Appearance > Themes. Upload the zipped copy of your child theme to your site and activate it.