Do You Need A Child Theme?

In: WordPress Tutorials - Intermediate

Do You Need A Child Theme

Creating a child theme is generally the best practice  for modifying or customizing an existing theme. However in a couple of cases there may be another, easier way, especially for beginners and non-coders.

Why Use A Child Theme?

If you need to modify your WordPress theme by editing any of the code, a child theme provides a way for you to do this safely. By “safely” I mean that it enables you to keep all your modifications separate so that you can continue to update the main, or parent theme in the future.

Let’s break that down a little further.

A theme is a set of files that lives on your server. In the screenshot below, I’m using an FTP program to look at my server but you would see the same thing if you used the File Manager from inside your web hosting cpanel. Once you navigate to the
wp-content folder you will then see the themes folder. Within that you’ll see a folder for each theme you have installed. In the screenshot below you can see some of the files and folders that comprise the Twenty Thirteen theme:

twentythirteen theme files

From time to time you’ll see in your dashboard a notification that there is a theme update available:

WordPress theme update available

When you click that button to automatically update a theme, all those files we saw in the first screenshot get REPLACED with a new set of files. It’s the equivalent of typing up a Word document and hitting Save. The new version of the document  replaces what was there before.

So what this means is that if you make a change to one of those theme files, and then it gets updated and replaced by a new version of the theme, the change that you made has gone! Poof! Kaput! If you have a backup you could re-add your code but that gets out of hand pretty quickly, especially if you modify multiple files.

Using a child theme protects you from this happening.

So What Is A Child Theme?

In literal terms a child theme is another folder within /wp-content/themes which has at least one file –  style.css in it. At bare minimum the style.css file has  a few lines of text in it that make the connection between it and the parent theme. The child theme might contain other files as well, but this is the bare minimum needed. In the screenshot below I have a child theme, ‘canvas-child’  which contains the few files that I am making changes to:

 

WordPress Child Theme - Files
When you go to Appearance > Themes in your dashboard, the child theme would be the one you activate, but it will only work if the parent theme also exists in the themes folder.

How To Create A Child Theme

As stated above, at its most basic, a child theme consists of two things:

1) A new folder in your /wp-content/themes folder on your server – you can name it anything you like
2) A style.css file in that folder with a few lines of code to connect it to the parent theme.

The WordPress.org Codex has a guide on creating a child theme and the basic code that goes into it. I usually start by copy/pasting this and then modifying as necessary:

WordPress Child Theme Style CSS

There are two really important parts here:
1) The template line which tells WordPress which the parent theme is. Make sure to name this the way the FOLDER on the server is named, not the theme itself. The theme may be title Canvas (uppercase C), but on the server, the folder is “canvas” (lower case c) so that’s how you would need to reference it in the “template” line of style.css

2) The import line is important to bring in all the parent styles automatically. After that you just add the code for the changes you want to make in your child theme style.css.

If you need to change one of the php files in your parent theme,  you will need to copy that file into the child theme folder and then change it. Any file that exists in the child theme takes precedence over the same file in the parent theme. The exception is functions.php which gets loaded in addition to the parent theme’s functions.php.

If you are comfortable using FTP or the file manager in your cpanel, making a child theme is not that hard. But for some people this could seem intimidating and for them there may be cases where it’s not necessary.

Sometimes You Don’t Need A Child Theme

If you are ONLY making changes to the CSS of your theme, you don’t need to make a child theme. Remember the point is to preserve changes and there are ways to change the CSS code which get saved to the DATABASE  this means it is protected from a theme update which only affects the FILES. So as long as your CSS is saved in the database, you can update your theme files and your modifications will remain intact.

For CSS-only modifications you can use one of the following methods:

1) My Custom CSS plugin

My Custom CSS WordPress PluginThe My Custom CSS plugin simply adds a box for code where you can add your custom styles. It saves to the database so will be unaffected by any theme changes. This is a really simple way to make a few modifications.

 

2) Custom CSS within your theme

Custom CSS in WordPress ThemeAny options that you configure in a theme or plugin get stored in the database so will remain after you update the theme files. Many themes these days feature a “custom css” box on the theme options page. This functions like the plugin mentioned above.

3) Jetpack CSS module

Jetpack CSS moduleIf you are already using the Jetpack plugin, it features a pretty nice CSS editor which will allow you to add your custom code. Again, it’s stored in the database away from the theme files.

Which route to go?

If you need to modify any PHP files you will definitely need a child theme.

But if you’re ONLY changing CSS sometimes it’s just easier to use one of the plugin methods. I find this to be the case particularly when meeting with clients who perhaps don’t have their FTP access handy or the right tools on their computer and we just need to make a couple of tweaks. It’s much faster to add something like the My Custom CSS plugin.

For users who aren’t comfortable with FTP and perhaps have found some copy/paste CSS code they want to use, it’ll be easier to slap that into a field in their WordPress dashboard than going through the child theme process.

If you have to do a lot of code, it’s much nicer to be able to work in your favorite code editor and FTP the files up to the server. So for extensive modifications I would use a child theme.

Questions? Leave a comment!

 

*header image credit

Weekly WordPress Tips To Your Inbox
+ Get 50% Off The Beginner's Guide To SEO Ebook!

Lucy Beer - WebTrainingWheels WordPress TrainingI provide a range of WordPress services from training at both beginning and advanced levels, to WordPress development and online marketing consulting.


13 Responses to Do You Need A Child Theme?

Avatar

Ree Klein

December 18th, 2013 at 10:24 am

Great post, Lucy. I now understand what a child theme is and when I should use one! Thanks,
Ree

Avatar

LucyBeer

December 18th, 2013 at 10:27 am

Thanks Ree! I appreciate the feedback!

Avatar

JTAdamson

December 18th, 2013 at 1:16 pm

I'm not a code monkey, and I'm using WooTheme's Canvass. It's nice because I can save my CSS, PLUS they have an "output theme settings" feature that I can use to export settings then import them back in later.

Avatar

LucyBeer

December 18th, 2013 at 5:37 pm

Hey JT, Thanks for the comment. I like Canvas for certain things as well. More and more themes are thankfully offering a way to export / save theme settings – definitely makes life easier!

Avatar

Brian Krogsgard

December 20th, 2013 at 6:49 am

I have to note that there is never any harm in using a child theme, but almost always a good reason to do so. I would encourage every user to use a child theme from the outset (in fact, I think WordPress should require such behavior). Reason being, if for some reason down the line the user does want to make a change, they already have the child theme setup and it is ready to go to accept a change.

Regardless of whether options like Custom CSS are available, a child theme is always a great idea for distributed themes.

Avatar

LucyBeer

December 20th, 2013 at 8:57 am

Thanks for the comment Brian. Indeed there would never be any harm using a child theme, but sometimes it's not realistic for non-technical users who can't stand the sight of their File Manager, assuming the modifications required are minimal.

Avatar

Keri Kight

December 25th, 2013 at 8:12 pm

When I first created my website, I was told by several people (and saw the same advice on several websites) that I should create a child theme – so I did. I have to say I'm glad I did because I am not a WordPress expert. Everything I've learned has been through Google (many blessings to Google).

Avatar

LucyBeer

December 27th, 2013 at 10:15 am

Hey Keri,
Thanks for sharing your experience!
Many blessings to Google indeed. When I first got into WordPress back in 2004, I learned everything through Google. These days there are tons of meetups etc that help, but it's incredible what you can accomplish just with Google!

Avatar

jacobperl

January 2nd, 2014 at 11:19 am

Thanks for this helpful article, Lucy. I have had one question about child themes, namely premium child themes designed for the Genesis framework, for example. What happens when the child theme provider updates the child theme? Are your customizations lost in that case, if you've only changed the CSS file vs. writing CSS to the database? What about if you've modified any of the child theme template files?

Avatar

LucyBeer

January 3rd, 2014 at 5:15 pm

Hey Jacob
That's a great question. If the child theme were to get an upgrade and you had modified the child theme directly then yes, your changes would be lost. If you were using a plugin like My Custom CSS to add your changes then you would be fine. Or you would have to keep track of the modifications you had made so that you could manually add them back in to the upgraded child theme. The same would go for modified template files. Typically theme companies will issue a changelog so that you could see exactly which files they changed – and therefore which of your modified files are at risk. This type of case where you're modifying a pre-built child theme definitely presents more challenges. I haven't come across a better way to handle things…..

Avatar

jacobperl

January 3rd, 2014 at 10:54 pm

Thanks Lucy, that's what I thought. I've been using Genesis Extender and had been debating whether to use its fields for CSS and functions vs. style.css and functions.php…now I can see why it makes sense to use the extender fields. There is also some provision for custom page templates and overriding WP templates so that those are preserved in a child theme update. But I'm wondering, with all this stuff in the database, whether the extra queries becomes a real performance issue or worth the trade-off.

Avatar

LucyBeer

January 4th, 2014 at 11:44 am

Hey Jacob
I haven't used Genesis Extender too much, but yes it definitely sounds like using the features it provides would be a smart way to preserve all your changes. I doubt that the impact of saving that stuff in the database would have any real impact on performance. I guess that would be an interesting test to run!

Avatar

Gina

February 14th, 2014 at 4:38 pm

Thanks. I am teaching small business owners who want to build their and manage their own sites but not get too techy. Thanks, this is nice and clear and what I thought.

Comment Form

Weekly WordPress Tips

+ Get 50% Off The Beginner's Guide To SEO Ebook!

How I Can Help You

Hi! I'm Lucy Beer. I know that WordPress is liberating when you know how to use it, and bewildering when you don’t. I help individuals and businesses learn WordPress for their specific needs. I will accelerate your knowledge and cut your learning curve in half (at least!). Generic tutorials and videos only go so far - when you need specialized knowledge, or a real person to answer your questions, that's where I come in. I help non-techies understand and use the web to empower their personal or business mission.

Learn How To Get Targeted Traffic To Your Site >> $20

Socialize

Services I Use & Recommend

Siteground Hosting
Sucuri
WP Engine
Gravity Forms
  • Dorothy at Shockingly Delicious: I just updated WP and I really miss not being able to highlight text with a background color. I didn [...]
  • LucyBeer: Thanks and you're welcome! I need to update it a little to talk about some of the new details i [...]
  • LucyBeer: Sounds like you'll need something like the "Members" plugin by Justin Tadlock [...]
  • Taimoor: How can we make certain part of the post password protected? [...]
  • mommyrunsit: I'm so glad I found this post! Thank you so much - it's been extremely helpful. I've [...]