WordPress themes can enhance the overall look and feel of a website, without any coding. You can customize different aspects of web design, such as color scheme, background color, font size and style, header, and a lot more to represent your site the way you want. But the problem occurs when you lose all the changes (modifications) after updating your theme with its newer version.

You can’t update your existing theme if you want to sustain the changes you made to it. But, if you avoid, your site will become more vulnerable to security attacks. Both the situations are dreadful for you.

To combat this situation, you should make a use of child theme. It can help you preserve all your changes (made into the theme) and lets you focus on enhancing the design of your site, without any annoyance. If you are not aware of this, then you should read this blog post.

Today, we will explore the meaning of child themes, why it is necessary for a WordPress site owner and the procedure of creating a WordPress child theme. So, keep reading the post!

What is a WordPress Child Theme?

A WordPress child theme acquires the functionality from another theme, known the parent theme to let you customize the WordPress theme, without ever losing the changes whenever you update it.

In simple words, a child theme empowers you to tweak the functionality of your site, without ever customizing the original (parent) theme template files. So, next time you update your existing theme, you won’t lose any changes (if you have a child theme).

Why Create a WordPress Child Theme?

Creating a WordPress child theme become necessary for every website owner who wants to update their existing theme, without compromising their custom changes. Below are the three major reasons for creating a WordPress child theme:

1. Updates

Earlier, updating an existing theme without losing custom styling and other tweaks was impossible in WordPress. It was hard to make the right decision. You would lose all the custom changes if you update your theme, and if you don’t, your site would become vulnerable to security attacks.

But, if you create a child theme, you will be able to preserve your modifications with ease, even after updating your theme. So, instead of editing the theme template file, you can create a child theme.

2. Spur up Development Time

Since the child theme will inherit all the design functionalities and styles from a parent theme, you don’t need to invest time in creating it from scratch. This will automatically accelerate the development time.

3. Organization

Incorporating additional code to an existing theme means you are adding hundreds and thousands of coding lines to a codebase. This makes it difficult for developers (who are working on your site) to figure out the changes you made. They will take more time as well as money to track down the modifications within your existing theme.

But after creating a child theme, a developer will be able to find out the modified code quickly and easily. This will save both time and money.

How it Works?

Once activating a child theme, WordPress will first search for the template files itself in the child theme folder. If there is no file, WordPress will fall back to the parent theme folder. For example:

If there is a “footer.php” file in the child theme, WordPress will use the same. And if not, then it will use the “footer.php” file in the parent theme. This is how a child theme keep the modifications in the safe mode whenever you update your existing/parent theme.

How to Create a Child Theme?

Creating a child theme is not as difficult as you think. All you need to do is to following the procedure given below:

1. Create a Theme Directory in Your WordPress Install

Here, we are using the twenty fifteen theme as an example. Just make sure that the name of your child theme directory is ended with ‘-child’. It should be something like this: twentyfifteen-child.

2. Create the Stylesheet for Your Child Theme

Once after creating a theme directory, you will need to work on creating your child theme’s stylesheet (style.css). All you need to do is to copy and paste the following piece of coding into your file:


/*
 Theme Name:  Twenty Fifteen Child
 Theme URI:  http://example.com/twenty-fifteen-child/
 Description: This is a child theme
 Author:	XYZ
 Author URI:  http://xyz.com
 Template:   twentyfifteen
 Version:   1.0.0
 License:   GNU General Public License v2 or later
 License URI: http://www.gnu.org/licenses/gpl-2.0.html
 Tags: 	light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain: twenty-fifteen-child
*/

Points to remember:

  • Theme name : It tells the name of your child theme, which is displayed in the theme selector.
  • Template : Add the name of your parent theme folder.
  • Don’t forget to replace the example text with your theme’s information.

3. Create a Child Theme functions.php file

The above step will help you run the child theme pretty well. It will reload all of your content once after activating it but, it won’t generate styling information. For that, we need to enqueue the parent as well as child theme stylesheets.

In order to enqueue the parent theme stylesheet, you will need to add a wp_enqueue_Scripts actions file into your child theme’s functions.php. And to do that you will need to create a functions.pho in your child theme directory using the following line of code:


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

4. Activating the Child Theme

Once after creating your child theme, make sure you compress it as “twenty-fifteen-child.zip”

  • Go to your WP admin panel > Appearance > Theme.
  • Install the child theme zip and activate it.

Note: Make sure that your parent theme is already installed on your WordPress site.

Conclusion

Give your theme a future-proofed environment by creating a child theme for your WordPress site. All the steps mentioned above in this blog post will help you develop a child theme for your existing parent theme using simple coding lines.

You can also hire a professional WordPress developer if you are not comfortable with the coding know-how.

Author

I am Brandon Graves an enthusiast blogger and web developer at WordPress theme customization company called HireWPGeeks. I love everything to do with WordPress, learning something new and sharing my experience with others.

Write A Comment

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