A child theme in WordPress: Answer to What, Why, When and How?

by WP Creative on 2017 April | Posted in WordPress

a-child-theme

So, I guess you own a WordPress website, right?

And your ongoing website has enough traffic.

Next day, your theme provider brings a new update of the theme you are using. In the excitement, you update the theme to bring new changes.

After a moment of the successful update, what you find is the changes you had made was overwritten by the default files. All your hard work in making a unique appearance of the website has gone.

You might feel like having a nightmare after spending a good day.

Now, your website has returned back to the initial phase from where you have started your website.

This is the drawback of using WordPress CMS.

But, wait. This is not the end. You can neutralise this complication.

You can use a child theme to overcome this situation.

Without wasting your time, I’d like to discuss all of your queries on:

WHAT is a child theme?

WHY is a child theme important?

WHEN should you use a child theme?

HOW to create a child theme in WordPress?

WHAT is a child theme?

According to codex.wordpress.org, “A child theme is a theme that inherits the functionality and styling of another theme, called the parent theme. Child themes are the recommended way of modifying an existing theme.”

Thus, I hope you understand that a child theme is a descendant of the main theme. This means a child theme requires parent theme to exist. A child theme inherits all features and files of the parent theme. If any changes are made on a parent theme, it’ll not be reflected on a child theme which prevents the overridden task of the entire theme.

But remember, you must have a sound knowledge of CSS and PHP to tweak CSS styles and the functionality respectively without touching the main theme.

WHY is a child theme important?

Updating themes, plugins or WordPress version maintains the security level of your website. So, you should not negotiate this. And, taking the risk of losing all your changes on the website in each update is also not preferable.

Thus, building a child theme is the best option. Besides this, having a child theme provides other benefits like

  • Speed up the development time of developers and designers.
  • Adds overall security of the site as the user can easily update the parent theme.
  • Ease the way to learn WordPress without breaking the original theme.
  • Ensure the flexibility to add new functionality.
  • Accessible to select a design that perfectly suits the user’s need.

WHEN should you use a child theme?

Creating a child theme is done as per your need. So, before considering how to build a child theme, you’d rather analyse when to create it.

For this, let’s see the following scenarios.

In the first case, you must answer these questions:

  • Do you want to customise the style of a theme?
  • Do you want to extend the functionality of the theme?
  • Do you want to change the existing template file?
  • Do you want to add new page template into the site?
  • Do you want to add extra custom fields?

If you think your answer to any of these questions is ‘yes’, then you need a child theme for your site. So, go for it.

In the second case, consider that you bought a premium theme. So, firstly, check whether your theme includes child theme within it or not. If it includes a child theme, you can easily use it for your convenience. Otherwise, you have to create a child theme by yourself.

Let’s assume another case where you want to customise your site using the WordPress Theme Customizer (from WordPress Dashboard).

Using the Theme Customizer to customise a theme will not touch your parent theme. In other words, we can say, your changes will not be saved in the actual file of a theme. In this case, you don’t need a child theme for your site.

The theme customizer lets the user configure Site Title and Tagline of a site, Manage Navigation Menu, Customise colour of a site, Change a background image, and Change the preview mode of the site (desktop/mobile/tablet).

HOW to create a child theme in WordPress?

WordPress facilitates its user to create a child theme with the use of plugins (if you wish). Some of these plugins are One-Click Child Theme, Child Theme Creator by Orbisius and Child Theme Configurator.

While on the other hand, the user can also do it manually. The following steps give the instruction to create a child theme manually.

Step 1:

To create a child theme, you need to create a new directory in the themes directory. After that, name that folder with the name of the parent theme, including “–child” at the end. You should not use spaces in the child theme directory. Then add two files style.css and functions.php in the child directory.

Step 2:

To create a child theme’s stylesheet (style.css). Your CSS file must begin with the following code:

/*

Theme Name: Your Child Theme

Theme URI: http://yoursite.com/

Description: Child theme for your new site

Author: Me

Author URI: http://yoursite.com/about/

Template: yourparenttheme

Version: 0.1.0

*/

Template line requires the name of the parent theme directory. So, give the corresponding directory name of the parent theme.

Now, it’s time to make the parent’s content available in the child’s stylesheet. For this, you can simply use @import: code. But, it takes a longer time to load the whole CSS.

The alternate way is to add a wp_enqueue_scripts action and use wp_enqueue_style() code in your child’s functions.php file. This shows functions.php of child themes append the child and parent theme.

The code goes like this:

<?php

add_action (‘wp_enqueue_scripts’, ‘enqueue_parent_styles’);

function enqueue_parent_styles(){

wp_enqueue_style (‘parent-style’, get_template_directory_uri() . ‘/style.css’);

}

?>

“ If your stylesheet file also includes actual CSS code then you need to enqueue it as well in functions.php”.

 Step 3:

At the final step, you need to activate your child theme by adding the theme as Appearance-> Theme-> Add New Section.

Hurray!!

You are now ready to use your child theme and free to make any changes without disturbing your parent theme.

At the end

Customising feature of WordPress makes it the most popular CMS. While you should not risk your whole site for new updates of themes. You have to follow this concept of creating a child theme and secure your site in each update.

If you have any complication in creating your child theme, you can ask us in the comment section.

  • One of the popular theme in WP world 🙂 cool one

Looking for a WP developer?

  • This field is for validation purposes and should be left unchanged.
  • Recent Post

  • Categories

  • © 2016 wp creative. All right reserved