If you are used to WordPress, you must have heard of a child theme. It is an excellent option if you want to change a purchased theme or allow developers to adjust to your website without affecting your core functionality. In this article, we will see what a child model is. We will see later why and how to create one.
What is a child theme?
A child theme is a design or template of a website or application that has access to the functionality of another theme (usually called a parent theme in web jargon). So if you update your theme, you won’t lose the visual changes and functionality of your parent site.
The main benefit is that it uses the functionality of the parent theme. Hence, we gain a lot of time in development. It saves you from writing a lot of code, and in addition, you can selectively modify only the model files and functions you need without going through other model files.
In addition, it is less complex than the parent theme. It is easy to continue a project since the child theme only focuses on the aspects to be adjusted on a website. However, when you are working on a child theme, and you forget to code some information, the functionality of the parent theme is still available as a fallback option.
Furthermore, the child design facilitates updates. You can make your update on the child theme. Therefore, there is little risk of overwriting the changes. For example, if a new version of the parent theme arrives, you can safely update it, as you made all changes in the child theme.
Another advantage is that it is easy to trace errors. Since the child theme essentially takes its functionality from the parent theme and includes the added changes. If a problem, it is easy to find the source of the fault.
The child theme has some limitations. Here are the limits if you use it.
One of the limitations of a child theme is the malfunction if the parent theme has bugs. When, for example, a child theme uses functions or classes of the parent theme, and the source theme developer removes this function, it can affect the website. Thus, it will cause issues on your site.
Moreover, if the theme developer stops maintaining it, it will impact updates of the child theme. Theme updates are essential for site security.
In addition, another limit is a time investment. When you work with child themes for the first time, it takes you a long time to familiarize yourself with the parent models to exploit them better. Therefore, it can slow down your development time.
Besides, a new disadvantage of a child theme is that a security flaw in the parent theme can impact the child theme directly.
How to create a child model?
In the following, we will learn how to create one. To achieve this, we will take one of the WordPress themes as a parent theme, “twentytwentyone”.
Step 1: Prepare your folder
It will be a question here of creating an empty folder that you will add to your WordPress site’s themes folder.
Step 2: Create and edit your style.css file
Creating a child theme is mainly about using the style.css file to define some basis. Fundamental, here is what you need. I would even go so far as to say that just a style.css file will be enough for you. The rest of the files you create will depend on how you want to work afterwards.
It is where it all happens. We will inquire about information such as:
- The theme name (the name of the child theme)
- Description of the theme
- Author’s name
- Name of the parent theme
- The name of the parent theme
The data is generally generic; you can use it in all your projects by making adjustments. The code below illustrates the data included in a child theme.
In the notation,
- “Template:” Matches the text domain of the parent theme. In the “twentytwentyone” theme, you find this information in line 13 of your style.css file.
- “Theme Name:” Matches the name of the child model. You can put whatever name you want.
You will find further information about the theme’s name or the structure via this link.
Step 3: Preparing the theme and installing the theme
Once you successfully complete the steps, you can then make some basic modifications such as:
- Add a screenshot of your theme — screenshot.png
- Create a functions.php file
- Duplicate the codes you want to modify by copying them from the child theme.
From this base, you can easily create pages, write custom functions. Redo or change anything you don’t like about the parent theme. In short, make a theme in your image without redoing everything from the beginning.
A few comments
- WordPress is so that changes from a file copied to the child folder automatically override the parent theme’s code. If you want to make modifications, for example, to the code of the “page.php” pages, you can make a copy in the child theme. The adjustments you make in page.php found in your new template will apply to the website.
- You can use the child model to disable features you don’t use. Indeed, WordPress has provided codes or filters that you can use for this purpose.
- The child model can be a good basis for creating a custom design. If you don’t like the look of the parent theme, you can use the child template to make a new theme. The advantage is that you won’t have to rewrite everything from scratch.
Despite the few limitations of this theme, it is advisable to use it for your website development projects. Meanwhile, if you are lacking in developing knowledge and want to meet an experienced developer, we are here. Contact us.