A beginner's guide to magento 2 child theme
You might have a vague idea of Magento 2 child theme. However, you might not know what it exactly is, why and how to use it.
This is a beginner's guide to Magento 2 child theme. In this post, we want to solidify your knowledge of Magento 2 child theme. There are 3 main points we want to discuss: child theme definition, the top reasons for using child theme, and how to create a Magento 2 child theme.
Magento 2 child theme definition
In Magento 2, a child theme is a theme that inherits the functionality and styling of another theme, called the parent theme. Child theme is the recommended way of modifying an existing theme.
There is no limit of the number of inheritance used.
The Magento 2 system is using Theme inheritance on the fallback mechanism. This means that if a view file's styling is not found in the current theme, the system searches in the ancestor themes, module view files or library for a replacement.
Top reasons for using child theme
Using child theme ensures the clarity of each individual theme.
Just like if you modify the website, you would use a backup. If you update your website's theme, you use a child theme. There are a couple of reasons for this:
- When the child theme is filled with so many bugs that you simply do not want to fix anymore, you can revert back to parent theme in just few clicks. This saves development time.
- When the parent theme is updated, the modification made to the child theme still remains.
Having that being said, if you really believe you can modify the theme with minor bug (which is hardly the case of real life) AND have no intention of any further update of the parent theme, go ahead and edit the theme source code directly.
Otherwise, use a child theme.
How to create a Magento 2 child theme
The only difference between creating a Magento 2 child theme and a Magento 2 brand new theme is the <parent> tag in theme.xml.
- If you want to create a child theme, declare the parent theme by <parent> tag.
- If you want to create a brand new theme, simply exclude <parent> tag in theme.xml.
You can browse our guide to create Magento 2 theme here. In this guide, we also suggest you create a child theme with Blank as a parent theme.
Magento 2 child theme: In conclusion
By now we hope that by now you have had a glimpse of the what, why, and how for Magento 2 child theme. As a developer, take advantage of child theme to successfully modify the theme without risk.
For your reference, you can browse our list of themes by clicking on the image from below.