If you create a website using WordPress, then sooner or later you’ll come across a useful nugget of advice – “Make sure you use a Child Theme”. If, like me, the first mention of a child theme elicited a “Huh?” then this blog is for you.
What is a child theme?
Let’s cover the basics first. What’s a child theme, and why should I consider using one.
Firstly, I’m assuming that you know what a WordPress theme is. If not, then playing around with child themes is a step too far. You need to go back in the paddling pool with your water wings before you jump into this deep pool!
OK, enough of the metaphors. As you know, themes are ways of implementing a website design in WordPress, often with the addition of extra functionality over and above ‘vanilla’ WordPress. Most modern themes allow a degree of flexibility over that design implementation. For instance, they will provide a means of uploading your logo. Often allowing you to easily change the colour scheme too. In short, they let you tweak the theme to make it unique to you and your business.
Great, so that’s all I need, right?
Well, possibly. But if you have worked with WordPress for a while, you’ll know that often there is a need to go beyond a theme’s built-in customisation. Let’s look at a typical example that we come across on a regular basis.
For many business websites, adding breadcrumbs to a site design is desirable. From an SEO point of view, they make it pretty obvious to Google (and other search engines) how your site is structured. From a usability viewpoint, they make it easy for a site visitor to work their way back up a hierarchy. This might be needed if, for instance, they follow an external link to a product page, and want to explore other, similar products.
Some themes include breadcrumbs as additional functionality, many others don’t. If we are building a site for a customer and the chosen theme doesn’t have breadcrumb functionality, then it’s fairly easy to add it.
Our usual method of adding breadcrumbs to a website is to utilise that aspect of the Yoast SEO plugin. This excellent plugin adds all the essential SEO functionality that most websites will need, and gives you a couple of nifty extras too, one of which is the ability to construct meaningful breadcrumbs. All you need to do is add a couple of lines of code to the relevant php files.
Add code? That makes me nervous.
Quite rightly so, adding code to a website shouldn’t be undertaken lightly. But lets just assume you, or your web developer, have taken all the necessary precautions and managed to add the code successfully. You now have breadcrumbs on all the relevant pages of your website and Google is happy!
In time, being a security-conscious site owner, you see that there are updates required on your site. You know keeping everything up-to-date is an effective way to plug security holes, so you take a backup, and start updating. The core WordPress update goes through, and your site is fine. Great, so you then update your plugins, including Yoast SEO. Again, no adverse effect on your website.
Finally, you see that there’s a new version of your theme available. So you go through the update process (sometimes this is a bit more involved than plugin updates), and your breadcrumbs disappear! How did that happen?
How do WordPress updates really work?
Whether you are updating WordPress itself, plugins or themes, the update process effectively downloads the new version of the plugin/theme, and overwrites the relevant files in your hosting account with the new ones. Any configuration that you may have done for the theme or plugin is retained, as all that information is stored in the database, and that is not touched by the update process.
If you remember, though, we implemented the Yoast SEO plugin’s Breadcrumbs by adding some code to certain theme files. So when the theme is updated, those updated files get overwritten by the standard files in the new version of the theme, which don’t contain the breadcrumb code. The end result: your breadcrumbs disappear!
A Child Theme will avoid that?
Yes indeed! Let’s have a quick look at the basic principle behind a child theme.
A child theme is similar, in principle, to looking at a picture through a filter. If the filter is clear, then you see the exact same picture as you would without a filter. If the filter, however, is tinted, then you see an altered version of the original picture, even though nothing has actually changed in the original.
A child theme is a filter for your active theme. It allows you to selectively alter aspects of that theme without having to change the theme’s files.
In slightly more detail, if a particular php file exists within a child theme’s file structure, then that file will be used in preference to the original file. So, with our breadcrumb example, we typically copy the relevant php files (e.g. single.php) to the child theme’s file structure and make the necessary alterations there. Then, when there is an update to the original theme, the original file can be replaced without the alteration made to the child theme’s version being lost.
So I only need a child them when I want to change something?
Technically, that is correct. However, it is much better to implement a child theme early on than wait until you know you will need to change a theme’s files. That’s why we’ve made it standard practice here at Four Lakes.
If you want to get your hands dirty and try implementing a child theme yourself, then there’s a great guide over at the ManageWP blog. However, the good news it that there are a number of plugins that will do the work for you, and utilise some of the lesser-know features of child themes to boot.
For other themes, the Child Theme Configurator plugin is pretty straightforward and effective.
Of course, if you’d like us to help you with this, or any other aspect of setting up or maintaining your WordPress website then all you need to do is get in touch.