All themes are not perfect. You want some change in your WordPress theme. Sometimes you find new functions or features in other’s WordPress site. You want to add in your theme. Or sometimes you want to the layout of your site. Want you can do for customizing the WordPress theme. You can use plugins. But sometimes WordPress plugins can’t resolve your issue. Like you want to a little part of the code in header or footer. Or you want to remove copyright text of theme provider. Creating child the is the answer.

What is A Child Theme

A child theme is also a theme which extends the another (parent) theme. A child theme may be a theme that inherits the functionality and styling of another theme, known as the parent theme. Child themes are the suggested method of modifying an existing theme.

There are a couple of reasons why you should use a child theme:

  • If you modify an issue directly and it’s updated, then your modifications are also lost. By employing a child theme you’ll make sure that your modifications are preserved.
  • Using a child theme will speed up development time.
  • Using a child theme may be a good way to find out regarding WordPress theme development.

How to Make a Child Theme:

A child theme consists of

  • The child theme directory
  • style.css
  • functions.php

The initial phase in making a child theme is to make the child theme directory, which will be put in wp-content/themes. It is better to name child theme as theme_name-child. Please make sure that there is no space in child theme directory name.

After creating the child theme directory in wp-content/themes, you have to create style.css file. The style.css should start with the stylesheet header. This header, which is in the comment, contains information about the theme. For more about stylesheet header please follow my post.

It’s just a sample. So you have to make some changes.

  • Change child theme name as you want.
  • In template use directory name of the parent theme. Template tell WordPress system about the parent theme.
  • Change other things as you want.

Ways to import parent theme stylesheet

WordPress system has two ways to import parent theme’s stylesheet. These methods to import parent theme’s stylesheet are:

  • using @import in style.css file
  • Enqueuing the parent theme stylesheet in functions.php file.

As @import method is not successful, so enqueuing the parent theme stylesheet is preferred. To import parent theme’s stylesheet create functions.php file in child theme directory and add a bit of code.

If your child theme’s style.css file also contains CSS you have to enqueue this also.

With this, you can enqueue parent and child theme’s stylesheet. Some points to note are:

  • get_template_directory_uri() retrieve the parent theme’s directory address.
  • get_stylesheet_directory_uri()   retrieve the active theme’s directory address. As this time child theme is activated. So it has child theme’s directory path.

Best plugin to create child theme

Yes, you can create the child theme with plugins. There are so many plugins available for creating a child theme. But i recommended you to use One Click Child Theme. This plugin is free as well as easy to use. You just have to click and fill theme and theme author name.

Modifying template with a Child Theme

Now let see how can you modify the code of particular template of the theme. It just simple, copy the file that you want to modify. And paste it in the same location of child theme as it in the parent theme. Like page template file is at wp-content/themes/your-theme/templates then paste the file in wp-content/themes/your-theme-child/templates. Now you can modify the file as you want. By doing so, file from child theme is rendered in place of parent’s file.

Extending functionality of theme

If you want to extend the functionality of your theme, you can add related code in functions.php file. Like if you want to add a metabox to existing post types. You can easily add related code to functions.php and retrieves its value in the related template file.

Conclusion

Modifying your theme with a child theme is always recommended. As you will not lose your changes on theme update. It’s simple to create a child theme. Even you can create a child theme with the plugin.

Hope you like this post. Your feedback is an applause for me.

Did you enjoy this article?
Signup today and receive free updates straight in your inbox. We will never share or sell your email address.
We hate spam. Your email address will not be sold or shared with anyone else.