This is not another “How to Create Child Themes” article. Rather than the hows let’s focus on the whys of creating child themes.
Figuring Out if You Should Create a Child Theme
While there’s no definite list of situations in which you’re better off creating a child theme than just editing your current theme, if what you’re trying to achieve could be described as any of following, child theme is the way to go:
- You would like to change look and feel of your WordPress theme beyond what can be done from Theme Options page AND be able to update your theme in the future
- You would like to change what some of your templates are showing (for example, add category description to category archives) beyond what can be done from Theme Options AND be able to update your theme in the future
There’s a pattern there – you want to make some changes that can’t be made from Theme Options page and keep the ability to update your theme. I can’t think of a reason not to keep a public theme up to date, so basically:
If you want to make ANY changes to your theme that can’t be made from Theme Options page, you need to use a child theme.
Note: If you’re using a fully custom theme that can’t be updated from dashboard, you really don’t need to create a child theme. What you want to avoid is…
WordPress Theme Editing Horror Story
You bought a nearly perfect WordPress theme, all it needs is a sprinkle of your creativity, of course. So, you either dig into it and start editing it yourself, or hire a developer to push your pixels. Several revisions later, you’re happy with it.
A few weeks pass, you absolutely love it, then WordPress notifies you there’s an update. You go for it, although worried it might break your site. Update goes well, your dashboard is still there, then you go to your homepage, can’t believe your eyes and begin to realize the importance of WordPress child themes.
What the Hell Happened to my Theme and How Can I Get it Back?
It’s called expected behavior and affects 100% of WordPress users who make changes to their WordPress theme files and then hit update button.
You can’t get your theme back unless you have made a backup of it after applying all the changes.
When I was just getting started as a WordPress developer, there was one common thing most experienced developers kept saying: “Never hack core files”. Editing WordPress core files and then updating WordPress meant losing all the changes you made.
Themes (and plugins) are no different. Once you hit that update button, there’s no “Are you sure you want to do this, I see you made some changes?” prompt. WordPress updates are a one way street, whatever you have in your installation will be overwritten by latest files.
How WordPress Child Themes Work
A child theme is required to have one file only – style.css – all other files are optional. Child theme’s style.css is used to override any parent theme CSS and change how content is being displayed in a WordPress website. Here’s what a Twenty Twelve child theme’s CSS file should look like:
/* Theme Name: Twenty Twelve Child Description: Child theme for the twentytwelve theme Author: Your name here Template: twentytwelve */ @import url("../twentytwelve/style.css");
Followed by any custom CSS your site needs.
To change what is being displayed, you need to edit one of template files. Any PHP file in child theme folder will override that same file in parent theme folder. So if you’d like to change what’s shown in your site header, copy header.php from parent theme to child theme and edit it there. If you mess up, you can always delete the file, pretend nothing happened and try again.
When you update the parent theme, child theme files are not affected by the update. Much better than losing all the changes you made.
And that’s the beauty of WordPress – anything can be extended. Themes and plugins extend WordPress core by overriding pluggable functions or hooking into action and filter hooks. Child themes extend parent themes in a similar way. You can and should use this to your advantage by creating child themes. If you’re eager to see one in action, check out Holi, a multi-colored Twenty Thirteen child theme.