DIY, Build a WordPress Child Theme.


“A child theme is a theme that inherits the functionality and styling of another theme, called the parent theme”. – WordPress.org

 

Using a child theme prevents you from losing any tweaks(made to your theme) when the theme is updated. You have spent hours making changes to your theme, making it your own. Why risk losing all those tweaks when you can create a child theme in less than thirty minutes? I have heard people ask “Well, what if I don’t plan on updating my theme?”. Technically, if you plan on never updating WordPress, then you might never need to update your theme. WordPress releases updates often, many of these updates are security updates. Some of them are major updates, which require developers to update their themes. What if your hosting company automatically updates WordPress and your theme is no longer compatible? You get the picture. If you use WordPress, at some point you will need to update your theme. Using a child theme is the smart thing to do.

Is Creating A WordPress Child Theme Difficult?

No, creating a WordPress child theme can be done in less than 30 minutes. As they say, it’s easy if you know how. For the purpose of this blog post, I will create a child theme for the free, default WordPress theme, Twenty Sixteen. The same process can be repeated for any theme, free or premium. Creating a basic child theme is a three step process.

1. Create the child theme directory – all themes are located in the wp-content/themes folder and this is where you will need to create the child theme directory. I created a directory called “twentysixteen-child”. The two files below will be placed in this directory(also called folder).

2. Create a style.css file – this file should be placed within the child theme above. This is your child theme’s stylesheet. Every stylesheet needs a header and you will need to place the following in your style.css file. Edit the Theme Name and Template to reflect your own theme. Particular attention should be paid to the Template – this must be the name of the parent theme directory. In this case it is “twentysixteen” – all lower case. The name of the template is case-sensitive.

/*
Theme Name: Twenty Sixteen Child
Theme URI: http://example.com/twenty-sixteen-child/
Description: Twenty Sixteen Child Theme
Author: John Doe
Author URI: http://example.com
Template: twentysixteen
Version: 1.1
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-sixteen-child
*/
view rawstyle.css hosted with ❤ by GitHub

3. Create functions.php – the next and final step is to create a functions.php file. If you don’t enqueue your parent and child stylesheets, the styles won’t render correctly and your site will look broken. Simply create a a functions.php file and paste the code below within.

<?php
add_action( wp_enqueue_scripts, theme_enqueue_styles );
function theme_enqueue_styles() { wp_enqueue_style( parent-style, get_template_directory_uri() ./style.css );
}
?>
view rawfunctions.php hosted with ❤ by GitHub

There you go, you now have a child theme. You can go ahead and activate it! Beyond stylesheets, your child theme can override any of the files in the parent theme. Say you wanted to make some changes to the header.php or footer.php, create a file of the same name in the child theme directory and it will override the one in the parent theme.

 Share This Post With Your Google+ Circle

Is There An Easier Way To Create A Child Theme?

If you are using the Twenty Sixteen theme, download the zip file by entering your email below. You will need to unzip the initial zip file and once unzipped, you will find two files: screenshot.psd and twentysixteen-child.zip. Upload twentysixteen-child.zip as you would any other WordPress theme and activate it. If you are using any other theme, download the zip, edit the style.css(as above), save it as yourthemename-child.zip, upload as you would any other theme and activate.

 

Don’t forget, the Template must be the exactly same as the name of the parent theme directory and is case-sensitive. A lot of people mistakenly copy the name of the parent theme from their WordPress admin area – don’t do that.

If, for some reason, you don’t have access to your control panel, FTP or themes section of your WordPress admin, there is also a free plugin – Child Theme Configurator.

Happy editing! Now, you no longer run the risk of losing all your tweaks.

Previous WEB DEVELOPER? ELEMENTARY PLUGINS NEEDED FOR WEBSITES..
Next Ten (10) African startups to watch in 2017

No Comment

Leave a reply

Your email address will not be published. Required fields are marked *