To child theme or not to child theme, that is the question?!

September 6, 2019 | Personal Blog, PHP, Themes, Tutorials, Wordpress | 0 comments

Is it the question? Well actually no.. it’s not a question at all. Not one that needs to be made in any case.

Let me reel back a bit.

What is a child theme?

A theme, such as Divi or GeneratePress contains all the files you need to make a site look and feel (and indeed function) correctly. These include things like the header, footer, sidebars and of course a huge amount of custom code and maybe a built in page builder. A child theme is essentially a cut down version of the same thing which relies on a ‘parent theme’ for it’s files unless overridden. Overridden being the key word there. If you wanted to make a change to the header for instance just copy the header.php file from the parent theme into the child theme directory and the site will use that instead.

Find out more about Child Themes straight from the horses mouth here

What happens when you want to edit one of these files and then the theme needs an update (as with themes like Divi there’s an update a week)? It overwrites the changes so you lose all your hard work. In order to help you understand this let’s look at how an update is processed with WordPress…

  • You press that magic update button (or WP does it for you via the automatic updates system)
  • WordPress grabs the latest theme (or plugin) from a remote server as a zip and copies it onto your site in a temporary location
  • The files are unzipped and checked
  • The old plugin/theme files are removed (or simply renamed to it can be restored on failure)
  • The new files are copied from the temporary location to the ‘live’ location
  • Checks are made and, if successful, the old files are removed
  • The update is complete

Now what happens to your edited code in the parent theme? Well, around step 5 they are simply removed without consideration or care of the amount of effort you have put in.

How can I make a child theme? Nice and easy, at the very least they are a few files in a certain format. Just follow the instructions on the WordPress link given above or if you are using Divi just use the Child Theme Generator which is a simple form you fill in providing a ZIP you can upload right away.

How does a child theme help?

Actually it helps tremendously. Consider that you overrode header.php or footer.php perhaps (as an example) using a child theme. When the update process takes place, ONLY the parent theme is replaced. The child theme, despite being linked to the parent is left intact. This way you can override files and write your own custom code (normally into functions.php in the child theme) without it being touched.

The functions.php file in a child theme is, to me, the most useful feature. Every child theme has a functions.php file and, unlike other files (header, footer etc..) this file is NOT overridden. Therefore, it’s a great place to place code snippets and other PHP items. I use them a lot for adding custom post types, custom widgets and other functionality items.

I can buy a child theme right?

Yes you can but that’s another purpose really. The main/original use of a child theme is to allow you to override certain aspects of a parent. Things such as CSS and bits of PHP. In the case of this post, I’m trying to explain why you might use one for convenience. Whilst this isn’t a marketing post, it is worth noting that buying a pre-packaged child theme isn’t a bad idea to get an instant site look and feel whilst remaining with the core ecosystem and support of the parent theme. Historically there have been thousands of themes created and released into the wild but most of them have been superseded by larger ‘multipurpose’ themes such as Divi, Generate WP, Astra etc.. You can retain the use of these larger themes and functionality whilst getting a fairly customised look through use of a child theme.

A huge market has appeared in recent years whereby designers will make a bunch of page templates, custom css, custom headers/footers etc and sell a package whereby you can transform your site simply by activating a new ‘theme’ (which is actually a child theme and therefore relying on a parent theme to already be on the site. Genius really and it has prompted a LOT of innovation from designers all over the world. Elegant Marketplace has a lot of these available to buy should you be interested.

A Warning

Well two or them and more advice really.

  1. Plugins, whilst using the same system to update, do NOT have a ‘child plugin’ system. Plugins are not meant to be overridden, they have a purpose and can be worked with using the action/filter system (commonly referred to at the WordPress API). If you want to override a plugin then consider why you want to do it and then learn a LOT of PHP as that’s what you’ll need to understand plugins and how they work,
  2. Overriding files in a parent theme is not without its risks. For instance if you override header.php and footer.php (essentially copy them from the parent into the child and make your changes) then you have more or less taken a snapshot of the parent theme at that point in time and those files will no longer be updated. Or at least the parent theme versions will be but the child theme files will override the parent and therefore the *new* code will never be used. Normally this isn’t an issue because you tend to choose a theme for how it looks and feels and developers rarely change large elements of their core files in that way. However, plugins such as WooCommerce allow you to override template files using the child theme (I won’t go into that now but read more here if you like) and these files are versioned which can be problematic if you override too many or too much.

I can just use a plugin or use CSS only right?

Back to the land of themes, you can make a lot of changes using raw CSS or plugins like CSS Hero (I’ve never used it but people do and like it and other similar products) and, in the case of a theme like Divi, there is a handy box for Custom CSS on the Divi Theme Options page. A lot can be done on a site using CSS but some things you do need to jump into PHP (editing WooCommerce functionality for instance or adding CPTs) and the functions.php file is the most obvious place to do this.

There are plugins that allow you to add code to a ‘settings page’ of sorts via a plugin. This feels like a bit of a workaround when there is a perfectly good system in place without having a plugin to update regularly. Plugins like this generally also store their snippets in the database and, whilst it’s mildly acceptable for CSS, I wouldn’t be a little hesitant to do so for PHP.

I’ve already got a live site, can I change to a child theme?

Yes and no. What’s good about child themes is that they have their own saved widget config, their own customizer settings saved and their own menu config. So when you activate a child theme on a live/configured site (especially using Divi where a lot of config is done in the customizer), you tend to lose all of your settings (logo config, typography, colours etc) so converting is a pain. That is, doing it the normal way. There are various free plugins available to seamlessly create a child theme and activate it without losing any settings. I have had success with this free plugin in the past though.

Conclusion

Adding a child theme is generally considered ‘best practice’, the system was put in place for a reason and it’s incredibly convenient. I’ve read various arguments for and against online but the ‘against’ camp seems to be populated mainly by people who claim to simply *manage without one*. The benefits of using a child theme are clear and adding one is effortless with absolutely zero potential for performance or security issues. I’m happy to hear arguments for and against.. please let me know in the comments what your take on this discussion are.

A Donate Button!

0 Comments

Submit a Comment

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

CommentLuv badge

Stay in touch!

Page Builder Cloud

Page Builder Cloud

A truly universal template library for WordPress Page Builders.

Page Builder Recommendation

Elementor Banner

We are BIG fans of the Elementor page builder. Give it a look!

About this site and Sean Barton

Picture of Sean
Sean Barton is a Freelance PHP Website Developer in Crewe, Cheshire. He is a Wordpress and CMS/Framework specialist and Co-Founder of Page Builder Cloud.
This site was set up in 2008 as a tutorial and scripting resource for the PHP language and Wordpress.
Find out more about Sean on the About Me page or use the Hire Me page to get in touch. For more information about Sean's work take a look at the Portfolio

Our Services

  • Wordpress plugin/theme development
  • Divi specialist
  • Ecommerce (Woocommerce, WPSC, Shopify, Magento)
  • PSD to Wordpress theme conversion (Responsive)
  • Website design work (Banners, Logos, Full Site, etc)
  • Website analysis (security, usability, SEO)
  • API Integrations (InfusionSoft, SalesForce, Ontraport, Customer Thermometer, etc..)
  • Wordpress consultancy & expert advice
  • Crisis support
  • Website hosting

The main services offered are Wordpress based although we do a great deal of technical programming for bespoke systems. From troubleshooting, extending frameworks, finding bugs to writing them from scratch.

Find out more by looking through our past projects or get a quote.

Be the first to hear about new products/updates!

This is a mailing list for those people interested in being told when we release a new product (Divi plugin or Theme).

We shall also use this list to let you know about product updates and releases.

You have Successfully Subscribed!