Why and how to always use a child theme.
Long story short, it saves all your theme customizations. So you can update your theme freely without ever losing your theme customizations:
- Customizer (settings)
- Style.css (modifications)
- Functions.php (modifications)
Most people customize their theme and website appearance in either of the three places above. They either choose or enter settings in the Appearance > Customizer, paste CSS code into the style.css, or paste code snippets into the functions.php file.
And while those are the proper ways to customize your theme, they have one big risk. The risk is if your theme has an update…it might overwrite your settings, style.css modifications, and functions.php hacks. So THIS is why everyone tells you use a child theme.
How to activate a child theme
Thankfully, it ain’t that hard.
- Go to your theme website and download their sample child theme. (For example, here’s the GeneratePress blank child theme).
- Go to your theme settings and “Export settings” to a file. If your theme doesn’t have an option to export settings, skip this part.
- Install and activate your child theme.
- Then re-import your theme settings into the child theme…or if you couldn’t export the settings previously, then you’ll have to re-do all your settings and customizations.
- OPTIONAL – go to the child theme folder and put your name and url into the top of the style.css (replacing the existing stock theme name). You can also put your own screenshot.png image (880px by 660px) so it looks like your site.
Does your theme not allow for child themes? Ouch, it’s probably an outdated one and should be replaced by a newer better WordPress theme.
What is a child theme anyway?
- You can think of “parent theme” as a complete theme, complete with all the coding and styling files needed.
- And a “child theme” as an addon to the parent theme, that has only the extra styling and functions that apply specifically to that child theme.
Child themes are useful because you can put all your customizations into the child theme, and then the parent theme is free to update often and you never lose your modifications. Child themes are also useful for developers to sell their own pre-made theme designs without having to code a brand new theme from scratch. You can think of it as like an iPhone case. The parent theme is the actual phone, and a child theme is just the design cover that goes over it. (Honestly not sure this is even a good analogy. But I hope you get the point.)
anisur rahman
does it affect performance?
i never used a child theme, thinking maybe it will slow down my website.
after seeing this post I am confident.
Johnny
No, it doesn’t affect performance in any way.
RogerM
Does a child theme is a better option to work on improving a site´s page speed performance rather than under a staging environment?
Also, what if the theme me or my clients are using doesn´t offer a child theme?
Johnny
I can’t answer that for you since it depends on your work style. I like to work directly on the live site…but that’s because I’m confident in what I’m doing. I’m not afraid of things breaking or that I won’t know how to fix them if they break.
Roger Marquez
Ok, let me rephrase the question…If you weren´t able to work directly on the site and you only had two options: Chile theme or Staging site…What would you choose?
Johnny
Definitely a staging site since that allows you to work on every part of the site, not only the theme.
Daan from FFW.Press
It’s been the first thing I’ve always done when building a WordPress site based on a theme. After I install the main theme, I install the child theme.
Love this post, Johnny. Core — yet forgotten — principles.
Arthur
Not true.
Child themes are only needed when editing page templates or creating new ones.
Themes updates will NEVER modify your existing Customizer settings – never – and the Code Snippets plugin allows you adding snippets in your functions file while WP Add Custom CSS allows you to add custom CSS to the whole website and to individual posts, pages and custom post types (such as Woocommerce products).
Johnny
No. Or maybe. Of course, you’re welcome to do as you please.
But I teach it my way because it’s cleaner.
– If your CSS and PHP hacks are specifically related to your theme, then it’s cleaner to keep it in your theme. (And definitely a child theme so there’s no chance of being over-written. Also, makes it clearer that this theme is modified.)
– If your CSS/PHP hacks are not theme dependent, then fine…it’s logically sensible to stick them in a separate CSS/PHP snippets plugin. (Although I prefer not having an extra plugin if I don’t need to. Fewer places to diagnose for issues and fewer places for clients to break things.)
For me, CSS almost always makes more sense when it’s attached to the theme. PHP snippets can be theme-related (functions.php), non-theme related (php snippet plugin), or even its own plugin entirely.
Whoever said “theme updates NEVER modify existing Customizer settings”…. there are a wide range of scenarios that can mess that up. Maybe clients resetting/restoring or re-installing a theme because of an issue, or who knows what. From my experience, it’s ALWAYS safer to have it in a child theme.
Online Buddha
Does adding a child theme secures the parent theme from being hacked? Sorry, but I’m so excited to know this.
Okwadia
I would Love GeneratePress child theme if I wanna build from scratch…