According to WordPress Codex, a WordPress Child Theme” is a theme that inherits the functionality of another theme, called the parent theme, and allows you to modify, or add to, the functionality of that parent theme“.
It is very easy to create a WordPress child theme from an existing theme (which then will become its parent theme).
Everything starts by creating a new directory inside the WordPress themes directory, giving it the name we chose for the new child theme. As soon as we put a properly formated style.css file inside that directory a new child theme is born, without having to wait for 9 months (just kidding) and even if we don´t include any CSS rule at all!
That´s right. We only need to include the appropriate comment lines in the information header of the style.css file to let WordPress know what is the name of our new child theme, what theme is its parent (acting as a template) and other optional information such as our theme´s version, the name of the autor, our uri, etc.
In this basic post we will not get into the details of creating a child theme, but there are lots of great posts and pages out there where you can get them. The only purpose of this post is understanding what a child theme is and what it is useful for. We´ll talk about why it is important for you to know if a particular theme is a child theme in this other post.
We will see how easy is to create a child theme in a future post. For the time being, all we need to know is that any style change made in the child theme to any element of the theme will override that of the parent theme, while any function added to the child theme will add to the functions of the parent theme.
Of childs, parents, twins and clones
Now, if we create a child theme that doesn´t add any new code to the parent theme, we will end up having a “new” theme that, although having a new name (and possibly a new “author”, description, etc.), is nothing but a mere copy of its parent theme. In other words, from my point of view that should never be called a child theme but a twin theme! (or a clone theme, for that matter).
But if we start adding or modifying styles and/or functions to our child theme, it will little by little begin looking different from its parent theme. The child therefore developes, “grows up” and ceases being a twin of its parent, acquiring its own “personality”. But even if the changes are numerous with a high level of customization, the child theme will still show some “family resemblance” to the parent theme, since it started by inheriting each and every of its features from it.
Preserving our work
At this point, somebody might argue that any level of customization could also be acomplished by directly modifying the parent theme, without the need of a child theme. So, why would we bother to create a new child theme?
The answer to that question is simple: because we don´t want to eventually throw all our work away.
Imagine you installed a new theme for your WordPress site and wanted to tweak it a little bit, for example by changing the fonts and some colors. You go to the theme´s style.css file and edit a few lines to make those changes. The results please you but then you think that it would also be nice to change some margins and paddings, so you edit the stylesheet again. And then later on you decide to change or add some functionality by editing the theme´s functions.php file. So little by little you´re adding a little tweak here and a little tweak there. Then you are finally proud of your customized theme, you love it and therefore you plan to keep it that way and to always use it for your site, whether it is a personal blog or a business site.
But one day you realize that, for whatever reason, you should update the original theme (think for example of a functional or security issue you hadn´t noticed before, or a bug you discovered in that theme that has already been fixed by its author in a new release of the theme). Now you would be running into trouble since everytime you update your theme to a new version you are actually replacing some of the old files with new ones, which means that you would be overwriting all your custom changes. You´ll be really throwing all your previous work away!
Even if you have a backup copy of the files you tweaked, you´d need to manually redo all the modifications to the new theme´s files again. It wouldn´t be safe to just replace the applicable newly installed files with your backup copies, since then you might be also deleting the changes made by the theme´s author to the new version.
The solution? Don´t ever touch the original theme´s files, start by creating a child theme from the first moment you want to modify something in your theme instead.
That way, you´d be free to update the parent theme everytime you want, without loosing your previous work. Since the changes in your child theme´s stylesheet will override the applicable rules of the parent theme, and your functions will add to the functions of the parent theme (you can even change them without touching the parent theme files), you will be effectively preserving your work.
Your child theme´s files will always keep untouched after a parent theme update, so your modifications to the theme features will never get lost, no matter how heavy your customizations were.
Otherwise, you would need to waste a lot of your time having the same “childs” and raising and educating them again and again!
Latest posts by Luis Alejandre (see all)
- All Top Ten WordPress themes are premium now - 18 December, 2017
- Child Theme Detection Just Got Better - 17 January, 2017
- Child Themes: Enqueuing the parent theme stylesheet instead of using @import - 31 December, 2016