“What’s a child theme?”
For a general WordPress developer, this is probably one of the most feared phrases outside of “I just changed something in the code and now my screen is white.” Okay, so maybe not that feared, but it is definitely frustrating to hear how many people aren’t using child themes for their customizations.
Child themes are lifesavers in the WordPress ecosystem. They save time, frustration and even revenue in some cases. Why? Because they protect your changes. With a child theme, you don’t have to make the same changes over and over after every theme update, and there is so much value in that.
So if you’re not using a child theme already, here’s why you should start today.
What is a child theme?
So before I argue why you should use a child theme, I need to define what a child theme is. Essentially a child theme is a theme to store any of your changes. It inherits all of the functionality and all of the styles of the designated parent theme, but it has the ability to overwrite any of that if you want to. Essentially, a child theme is a place to store your style changes.
The best example of this is the Genesis framework.
StudioPress created a page with a more detailed look at what Genesis is, but here’s a very simplified look at it.
Genesis is a simple theme that has all of the functionality a theme needs to run. But the theme base theme is very bland. However, it’s written in such a way where anyone can make a child theme of Genesis and customize it to meet their needs. There are a ton of hooks and what not a developer can use to customize it. And you don’t have to worry about creating every single template.
A great way to stay organized
Ever had a moment where you’re just trying to find a piece of paper in a stack and gosh darn it you just put it over there where is it? Frustrating isn’t it?
Making changes to your site’s styles and functionality can be a similar experience when you don’t use a child theme. It causes frustration and loss of time, which can also mean the loss on money.
Have you looked at your base theme’s style.css file? Have you noticed how many lines of CSS there are in it? For my portfolio theme, I have over 6500 lines of CSS before I get to any sort of custom styles. Now, of course that’s importing all of the Foundation and Font Awesome styles and I use SCSS to keep things organized, but most themes that are being used have at least that many lines in total.
You do not want to crawl through that many lines to make one change. Even if you put every change at the bottom, you’re still scrolling a lot to make changes. That takes time.
With a child theme, the style.css file is smaller, and you can do anything you want to with it. You can organize it anyway you want it, and you know exactly where all of the changes have been made. And most importantly, that saves you time, frustration and potentially revenue. It’s worth it.
Protects your changes during a theme update
But most importantly, using a child theme protects all of your changes from an update to a parent theme.
When you update the parent theme, everything in that parent theme is going to get overwritten. And when I say everything, I mean it. Styles, functions, templates, everything is erased in favor of the new version of the theme. So when you update the theme, you’re killing all of your changes.
But don’t take my word for it. Earlier this year, a
Presbyterian church had a member working on the website and he accidentally updated everything — WordPress, plugins and the theme. Normally, this wouldn’t be much of an issue, but the previous developer had created their theme with one of the basic Twenty-something themes that come with WordPress without using a child theme.
So, when the member updated everything, all of those changes were overwritten, church effectively no longer had a functioning website. The data was still there, but it wasn’t really usable. Fortunately, they came to us at Faith Growth and we were able to give them a better site with better practices.
So don’t be like them. Don’t put yourself in a position where all of your work can be destroyed with a click of a button. Sure, as you’ll see below, it’s a little bit of work to set up a child theme, but it is so, so worth it in the end when you don’t have to worry about changes being overwritten.
So what are you waiting for?
How to create a child theme
Creating a child theme is relatively easy, although I can see how daunting it might be to one. But here’s a brief guide on how to do that.
First, you’re going to want to create a new directory (or folder) in the wp-content/themes directory. You can do this either through FTP or your host’s file manager. You’re probably going to want to name the new directory something similar to the parent theme, like giornalismo-child.
Then in that new directory, you’ll need to create a style.css file and a functions.php file. In the style.css file, place the following code.
/*
Theme Name: Twenty Fifteen Child
Theme URI: http://example.com/twenty-fifteen-child/
Description: Twenty Fifteen Child Theme
Author: John Doe
Author URI: http://example.com
Template: {parent-theme-slug}
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
Be sure to change the parent theme information to your parent theme’s information. Then in the functions.php file, put the following code.
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
That should do the trick. You now have child theme where you can make all the changes you want without the fear of the changes getting overwritten.
Helpful Links