When it comes to WordPress theme customization there are two main approaches. Traditionally, because WordPress is open source you’d just make your edits directly to the theme itself.
Very early on the WordPress core developers added the ability to use a child theme. A child theme inherits all of the templates and functionality of the parent theme while allowing you to modify the parent theme output because the child theme files supersede the parent theme files.
Advantages of Using Child Themes
Making all of our customizations in a child theme instead of directly to the parent theme has some distinct advantages.
- Protection – Theme developers regularly push out new releases with improvements, bug fixes and the like. When you modify the theme directly upgrading the theme with a new release from the developer will overwrite your customizations. When your customizations are in a child theme then they are protected and they aren’t lost when the parent theme is upgraded.
- Speed – Working with child themes can speed up website development time. This is especially true with a theme framework system like Genesis. Because much of the heavy lifting on the back side for things like search engine optimization features, widgets and layouts, etc. is already done in the child theme, you don’t have to recreate the wheel every time you start a new project. And then theme frameworks like Genesis stepped that up a notch by including hooks and filters throughout their code to make modifying what the code does even easier.
- Education – Customizing via child themes is a great way to get started learning how WordPress works while minimizing your risks. One of the best ways to start learning WordPress is to dig into the code itself and see what effect changes have. When you make all of your changes in a child theme, you have the safety net of being able to fall back to the parent theme functionality if you get stuck or break something that you have to undo.
What is Required for a Child Theme
In its most basic form, a child theme can be simply a folder that contains a CSS stylesheet. (A stylesheet is simply the style.css file. Those terms are interchangeable.) When you look at the header of the style.css file you will see a top section inside comment marks with some information about the child theme. Here’s an example from the current version (as of this writing) of our Kathryn theme:
/* Theme Name: Kathryn Description: Katheryn is a clean professional theme especially for accountants built on the <a href="https://web-savvy-marketing.com/go/studiopress/">Genesis framework</a>. Author: Web Savvy Marketing Author URI: / Version: 1.0.8 Template: genesis */
The only two parts that are required are the theme name, which is what the child theme is called, and the template reference. The template reference must be the exact folder name of the parent theme and not the parent theme’s name.
Including that key line template: genesis tells WordPress that this is a Genesis child theme. When that happens, WordPress will use all of the template files from Genesis that aren’t duplicated in the child theme folder.
Of course because the one required file in the child theme is style.css, that means that file completely replaces the style.css file from the parent theme. So the child theme doesn’t automatically pull in the styles of the parent theme.
There are two ways to overcome this. You can use an @import line at the top of your stylesheet to include the Genesis styles. This can be quicker in some instances, but can lead to unexpected results.
The other option, and what you see with most Genesis child themes, is to include all the styles the child theme needs without pulling in the parent styles. If you are starting your own child theme you can simply copy all the styles from the Genesis stylesheet and start modifying them in your child theme.
Duplicating the parent’s style sheet rather than importing it has the advantage that all the styles for your child theme are in one place. Also it reduces the likelihood that changes in the parent theme styles will alter your site when you upgrade.
Additional Child Theme Files
Once you get past the minimum requirements, a child theme can include any of the files from the Genesis theme as well as additional WordPress template files.
Most of the time you will see a functions.php file. This file is the first place WordPress looks to see what PHP functions to execute in your theme and it’s the one exception. The functions.php file is the one file that does not get overridden in the child theme.
Depending on how complex the child theme is, the functions.php file may reference other files. And that’s how you can work through what the child theme does and how it does it. Look at the functions.php file first. Then follow the code through the referenced files.
In it’s most basic form a child theme can be very simple. Our custom design and stock themes have a bit more going on so you’ll find a dozen or more directories with scores of files.
Yet even with that complexity they still boil down to the child theme basics.
Customizing Your Child Theme
At this point there is no good way with WordPress to create a “grandchild” theme, or a child of a child theme. There are some work arounds. But they tend to be clunky and a bit confusing for folks just getting started.
Later in this series I’ll be sharing how to manage your own customizations. For now though the place to start, where most of your own tweaks and changes will take place, is in the style.css file and the functions.php file.
Now it’s your turn. What is your biggest child theme customization question?
This is the second in our series of articles on Best Practices for Genesis Theme Customization.
David Wang says
Great point about education. Looking back at my WordPress learning curve it definitely jumped when I started developing with Genesis and using the child themes paradigm. Looking forward to your tips on managing customizations 🙂
Chris Cree says
Yep. The best way to learn is by doing. I tell people who are looking to get started that they should have their own website where they can tinker and learn.
With low end shared hosting only costing about $10 a month and a domain for $15 a year or less it’s an inexpensive low-risk way for folks to test the waters and see if this is for them. If they find they like it and have an aptitude then they can build their skill set to the point where they can start getting paid to help others too.
Dave says
I have a theme customisation question..
I am interested in building my own child themes. I have started changing the css so much after buying a child theme that I am happy to start from scratch and try and do it all myself. The part I am struggling with is.. when I want to create a file such as home.php, how do I know which piece of code to use if I want to create a widget area for example? For now, I can easily go to one of the child themes which i have bought and see the code they used and work out which code is doing it and recreate. But there is also things that I will want to do that the child themes I have do not. Where do I look for this code? I know about the code snippet area on the studiopress website which shows a few genesis functions but there are not many there. There are so many functions specific to Genesis that people seem to use, but I don’t know where they are getting this information from?
A quick example in case you don’t understand my queston.. in the child theme I currently have it has the code
add_filter( ‘genesis_site_layout’, ‘__genesis_return_full_width_content’ );
but I can’t find any documentation about where these parts of the code came from?
Marco says
Hello,
just look in /wp-content/themes/genesis/lib/functions/layout.php
If you spend some times looking in Genesis folder you’ll find code is well documented there.
M.
Rob Cubbon says
I used to import the theme framework styles to my child theme’s CSS when doing child themes for Twenty Ten. One benefit was that it’s easier to find relevant bits of your child theme style.css when tweaking your child theme.
However, now I like to simply have the full CSS in the child theme’s style.css. And that’s how they are when you get them from Studiopress.