Easy Explanation for Creating WordPress Child Theme

What is a Child Theme?

Child theme is a small and simple theme that inherits functionality and styling of its corresponding parent theme and gives you ability to tweak the parent theme. (You may call child theme as a theme specific plugin, it acts like a plugin if the parent theme is activated along with the child theme.)

When Should You Use a Child Theme?

  • The most case is, If you want to modify the stylesheet of your main theme.
  • If you want to modify how your WordPress theme is working. That means to customize the function of the theme or if you want to edit ‘functions.php‘ file of the theme.

Why Use Child Theme

It is highly recommended to make a child theme for editing ‘functions.php or ‘style.css‘ of a theme. Modifying a theme directly is not good method and the modification will be lost after update, while modifying using a child theme preserve your modification even after update. So child theme is smarter way to modify a theme.

Creating a Child Theme

Child theme mainly consists of a directory and two files which are ‘functions.php‘ and ‘style.css‘. Imagine we have to create a child theme for Twentythirteen Theme. So,

  1. parent theme name: Twenty Thirteen
  2. parent theme directory: twentythirteen
  3. child theme name: Twenty Thirteen Child
  4. child theme directory: twentythirteen-child

child theme directory must end with ‘-child‘ i.e. directory must be in ‘parent_theme_directory-child‘ format. The parent theme directory can be found in wp-content/themes/.
Structure of your child theme looks like this:

  • twentythirteen-child/
    • functions.php
    • style.css

Now create a directory ‘twentythirteen-child‘ in your PC and inside it create a file named ‘style.css‘ and fill the given infomation as outlined below:

example.com corresponds your website address while the theme uri is address to to your child theme and template is your parent theme directory name.
Then create a ‘functions.php‘ file and paste the given code:

This will enqueue parent theme style and child theme style. Previous method was to import the parent theme stylesheet using @import: now this no longer recommended because it increases the amount of time it takes stylesheets to load decreasing your site performance.

Description:


Now you you are ready to upload the child theme. Upload the twentythirteen-child folder and the files to ‘wp-content/themes/‘ directory using ftp and activate the child theme. Now you can modify stylesheet and functions.php files as your wish without worrying about the future updates.
If you want to change more than just the stylesheet, your child theme can override any file in the parent theme: simply include a file
If you want to modify template files also copy the original template file, modify it and upload it to the same directory of your child theme. Then your modified template file in child theme directory loads instead of original one. Example is to modify ‘header.php‘ file.
Unlike stylesheet and template files in child theme that overrides the original theme files, ‘functions.php‘ of your child theme doesn’t override the original.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.