Join Morten Rand-Hendriksen for an in-depth discussion in this video When to use a child theme, part of WordPress Workflows.
- The second workflow we'll look at is customizing your site with a child theme. This bring up two questions, what is a child theme and when do I need and want to use it? Let me quickly answer these before we get going. In WordPress, the theme is what defines the appearance of your content on the front end. When you first installed WordPress, you get the default theme, and that's what displays your content. So right here, in my site, you can see my content displayed using a twentyfifteen theme. When you want to change the appearance of your content, you change the theme by going to the back end of your site, going to Appearance and Themes, and either activating one of the pre-installed themes or navigating to find new themes in the WordPress theme directory.
Most themes also come with some support for the WordPress theme Customizer. From here, you can change the appearance and behavior of the theme. For example, in this theme, twentyfifteen, I can change the base color scheme to any number of other presets or I can change the colors manually. While a lot of free themes come with limited sets of options in the Customizer, for-pay, premium themes may have a lot of options, and in some cases, have whole different pages full of extra theme options. In addition to the Customizer, you can also change the appearance of your site by adding widgets and plugins, but for the most part, these just alter the content displayed.
They don't control the actual presentation of the content. When you want to customize the current theme you're using, you create what's known as a child theme. This is a mini theme that inherits all the features of the original theme, or parent theme, and allows you to change just the pieces you want while leaving the rest of the theme alone. I've created a small example to show you here so you understand what the difference is. So, right now we are looking at my content using the default theme that comes with WordPress called twentyfifteen. You can see here it has a regular serif font for all the content.
Now, I've created a child theme. You can see it here in my text editor. It's called twentyfifteen-child, and it has a small set of new styles that change the font families to use Google Fonts, and also changes the underline for links. So right now, we have a standard sans-serif font here, and you'll see that the links are underlined with a black line. When I now go and change my theme to the child theme and jump back to the front page, you'll see the fonts have changed. I now have a sans-serif font as the heading and a different serif font for the body text.
And for my links, instead of the thin, black underline, I now have a thicker, light blue underline. Going back to my code editor, I can show you that this child theme only consists of two files. You see it here, the folder, and then you have a file called functions.php, which contains only one function that brings in the original style sheet and also the fonts from Google Fonts. And then we have the style sheet for the child theme, which only has these three rules, one for all the body text, one for the headings and one for the link underlines.
What actually happens when you use the child theme is you take the parent theme, then you create child-theme versions of whatever files you want to change, and you only make the changes you want in that child theme. So everything else stays the same, and you'll end up using the parent theme files unless you specify other files in the child theme. So when do you use the child theme? Anytime you want to make a change to the appearance or behavior of your current theme. Rather than trying to change the original theme, you create a child theme, make the changes there and activate it.
That way, updates to your parent theme will still take place on your site, and if something goes wrong in your development of the child theme or your child theme starts acting up, you can always go back to the parent to ask for help or to just take over by deactivating the child theme all together. As before, I'm not going into detail about how to create a child theme in this course. Instead, we're looking at the workflow surrounding the creation and application of a child theme on your site. For a full tutorial on how to build your own child themes, check out the course "WordPress Building Child Themes" right here in the lynda.com library.
- Setting up WordPress on a live host
- Setting up a local development environment
- Creating and publishing content
- Managing media
- Adding a new child theme
- Building custom sites for clients
- Syncing content between local and staging servers
- Making a site live