Child Theme Template in WordPress


If you want to modify existing theme then create a child theme. It is a best way. It inherits the styles and functionality of the existing theme which becomes the parent theme. In this tutorial you will learn about creating a child theme template.

What are the reasons to use a WordPress Child Theme?

Following are some reasons to use a child theme in WordPress.

  • If you are using a third-party or premium theme and you want make some changes in this. These changes should be done in child theme because when you get an update in main theme all changes will be overwritten.
  • As main theme is created by third-party, it is safe to do all changes in your child theme.
  • If you want to add new feature or style you should do it in child theme.
  • Premium themes are modified frequently.

How to create a Child Theme in WordPress?

  • Create a folder in themes where your parent theme exists. Directory name recommended to have a suffix ‘-child’. For example if parent theme name is ‘tricksofit’, now recommended child theme folder name is ‘tricksofit-child’.
  • Create style.css in this folder and it should have below information in header comments.
  • Create a functions.php file in this folder.

Now you are ready with your minimal child theme just make it activated.

Child Theme’s style.css

Child theme’s style.css should have below standard comment. You can use the following as template.

/*
 Theme Name:   Tricks Of IT Child
 Theme URI:    http://example.com/tricksofit-child/
 Description:  Tricks Of IT WordPress Child Theme
 Author:       tricksofit
 Author URI:   http://www.tricksofit.com/
 Template:     tricksofit
 Version:      1.0.1
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, two-columns, three-columns, left-sidebar, right-sidebar, fixed-layout, responsive-layout
 Text Domain:  tricksofit-child
*/

Template is the directory name of the parent theme.

Child Theme’s functions.php File

In child theme folder create a file functions.php and add the following script into it. This is to enqueue stylesheet of  the parent theme.

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

Above script will include parent theme’s style.css file.

You can add below line in style.css file of your child theme to include parent theme’s style.css file :

@import url("../parentthemefolder/style.css");

Hope this tutorial will help you to create a child theme template in WordPress.