According to the latest surveys, over 87% of the WordPress web developers customize the themes they use. Yet, only 34% use a child theme in the process. In this tutorial, I am going to explain to you what is a WordPress child theme, how to create and use it. In just a few simple steps you will learn what, how and why you should use a child theme. It is easy and it will spare you of a lot of troubles in the future.
What is a child theme and why you should use it
A child theme is just a copy of your original theme. Nothing more. You should use it in order to be able to customize your website without taking the risk of ruin the original code. This way, if something goes other than expected, you can return to the initial version of your page with just a few clicks. It is also very useful when your theme needs to be updated to a newer version. You will be able to do that without losing the adjustments you did.
How to create a child theme in WordPress
For exemplification purposes, we will consider Twenty Fifteen WordPress theme. It comes free with any WordPress installation so you should find it in your theme folder.
The first thing you need to do is to create a new folder for your child theme. The standard name is the name of the theme followed by the word child, like in the below example.
For the second step, you will have to create in the new folder a file called style.css and copy paste the below code. Please make sure you replace the name, description, author and URL with the ones you have.
/* Theme Name: Twenty Fifteen Child Theme URI: https://wordpress.org/themes/twentyfifteen/ Description: Twenty Fifteen Child Theme Author: WordPress Author URI: https://wordpress.org/ Template: twentyfifteen Version: 1.0.0 */ @import url("../twentyfifteen/style.css"); /* =Theme customization starts here ------------------------------------------------------- */
The most important parts are Template and @import, as they identify the parent theme which will be used as a reference. Don’t forget that everything is case sensitive!
How to activate a WordPress child theme
Now that all this has been done you can activate the child theme as you would with any other regular theme. Go to Dashboard -> Appearance -> Themes and activate it.
How to customize a child theme
As a result of all of the above, you will have an identical theme like the original one. To customize it all you need to do is to add the new CSS commands to the style.css file in the child theme folder.
The theme’s functions can also be adjusted. Initially, the functions.php file of the parent theme is inherited, but you can create a new function.php file in the child theme. Add here whatever functions you like. This file will be considered first, then the one in the parent theme folder. In this way, you will benefit from both. Make sure your child theme’s file starts and ends with PHP tags.
<?php // Your php code goes here ?>
Editing other PHP files is possible, but unlike modifying the functions file, these are not inherited from the parent theme. Before modifying them, you will have to copy them manually in the child theme’s folder. When you do that make sure to recreate the exact path! The new file will be taken into consideration while the one of the parent themes will be ignored.
How to create a child theme automatically in WordPress
If you find all this process a little too complicated for you don’t despair. As almost everything else in WordPress, a child theme can be created using a plugin. Rather than doing this manually, I recommend One-Click Child Theme plugin. Of course, there are other plugins that could suit your needs. Feel free to try them out and let me know of the results.
Hopefully, I managed to clarify thing for you in this matter. Let me know if you have any other questions or concerns regarding the creation of WordPress child themes. Thanks!
Tip: if you are into WordPress customizing check these articles:
- What is an RSS feed and how you can use it
- How to create an RSS feed for each category in WordPress
- How to truncate an RSS feed – display only a part of your post