In this article, I shall be discussing WordPress child themes: what they are, their advantages (and disadvantages), as well as how to get started with WordPress child theme development, and additional resources that you should surely check out!
In simple words, a child theme is a WordPress theme that borrows template files and other relevant functionality from a different theme. Thus, let us say, if we were to create a custom theme that borrows functionality and templates from Twenty Seventeen, the WordPress default theme, our new theme will be called a child theme of Twenty Seventeen, which in turn shall be termed the parent theme for our child theme.
As such, since most of the functionality and template files rest with the parent theme, the child theme often has nothing more than a single style.css file which specifies what functionality is to be derived from the parent theme and what aspects of the parent theme are to be changed or modified in the child theme.
Thus, the primary motive behind a child theme is to customize or tweak a given parent theme in order to make it suit our needs, and at the same time, not play around with the actual theme files because if the parent theme is ever updated, we may lose our changes.
The advantages of using WordPress child themes are many, such as:
While there aren’t many drawbacks associated with WordPress child themes, following are certain caveats that are well worth noting:
So, you have already decided to create a child theme for your favorite WordPress parent theme? Well then, let us get going!
First up, you need to create a folder for your child theme in the WordPress theme directory (nomenclature doesn’t really matter). Thereafter, create a style.css file in the folder, with the following details:
Theme Name : The name of your child theme
Theme URI: http://www.example.com (Your child theme’s URL)
Description: A brief description of your child theme
Author: Your name
Template: Your parent theme directory name
Version: 1.0.0 blah blah
In this, under the Template part, you need to specify the directory name of the parent theme concerned. Also, if you omit that line, WordPress will treat your child theme as a proper theme in its own right.
At this junction, we have a child theme with a blank style.css file. Now, to inherit the stylesheet properties of our parent theme, add this line:
Replace the ‘parent_theme_directory’ part with the name of the folder where the concerned parent theme resides.
You can also import multiple stylesheets using this method, if need be.
Now, your child theme is ready to inherit stylesheet elements from its parent theme. If you want, you can also copy these folders from your parent theme’s directory to your child theme’s folder (not mandatory, but advisable), all addresses being relative to the parent theme directory:
/rtl.css (Right-to-Left language support, not all themes may have this functionality).
That’s all. You can now start adding your custom stylesheet settings to the child theme’s style.css file. Additionally, you can also copy template files from the parent theme to the child in order to edit them, and if you need to add new functions, make sure you copy the functions.php file from the parent theme’s folder to the child theme’s directory.
Once you activate your child theme, WordPress will load the stylesheet settings and template files from the child theme itself, and if anything is missing, it will load the corresponding entities from the concerned parent theme.
If you wish to explore WordPress child themes in even more depth, I recommend you check out these articles and resources:
Child themes not only provide an effective medium of extending the functionality of your favorite WordPress theme but also serve as a good startup point when it comes to learning and mastering WordPress theme development.
What do you think of a WordPress child theme? Have you developed any or are trying to get started with one? Share your experiences with us using the comments below!
Send this to a friend