In WordPress, just like in real life, a child doesn't have to look like its parent

Importance of WordPress Child Themes

Share

This is not another “How to Create Child Themes” article. Rather than the hows let’s focus on the whys of creating child themes.

If you’re already aware of importance of WordPress child themes and just need to learn how to do it, check out WordPress Codex page or Child Themes Basics tutorial at WPTuts+.

Figuring Out if You Should Create a Child Theme

In WordPress, just like in real life, a child theme doesn’t have to look like its parent

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.

The following two tabs change content below.
I love working with WordPress and doing it the right way. Themes and plugins I develop have a common #1 goal: Keeping it as simple as possible for users to publish their content.

Latest posts by Slobodan Manic (see all)

5 thoughts on “Importance of WordPress Child Themes

  1. I remember back years ago, hacking away at a theme, I spent weeks on then click…. All gone. Ever since then I’ve been building out child themes. Great overview Slobodan !

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>