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 formatted 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!
The basics
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 authors, 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 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 children, 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, develops, “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 one of its features from it.
Preserving our work
At this point, somebody might argue that any level of customization could also be accomplished 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 every time 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 every time you want, without losing 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.