How to Create Child Theme in Magento 2
Themes in Magento 2 defines the look and feel of your store. Having the graphics and appearance details, the parent theme customization is not advisable.
Hence, the theme inheritance!
(Note: There is no limitation for the level of the theme inheritance)
If you want to customize the appearance, it is sane to create child theme in Magento 2 rather than implementing the changes in the parent theme. Because, if the changes are directly implemented in the parent theme, upgrading the Magento version results in loss of theme changes in the parent theme. Banner displayed in the frontend is not designed keeping in mind any custom theme designs. The solution to this issue is to Overriding Extension Files Using Your Magento 2 Theme.
To easily extend the theme and minimize the maintenance tasks, create child theme in Magento 2 and customize it. By definition, the child theme is a theme that inherits all the properties of the parent theme. It is useful to customize the existing parent theme design as per the requirements.
Steps to Create Child Theme in Magento 2:
Before following these steps, note that “Meetanshi” is the vendor name and “luma” is the parent theme name.
- Create a child theme folder named as {parent-theme-name}_child in the following folder path.
1Magento root folder/app/design/frontend/Meetanshi/luma_child - Create file theme.xml inside the child theme to specify the parent theme inherited by the child theme
12345678<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd"><title>{Child Theme Name}</title><parent>{parent-theme-vendor-name}/{parent-theme-name}</parent><media><preview_image>media/preview.png</preview_image></media></theme>
12345678<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd"><title>Luma Child</title><parent>Magento/luma</parent><media><preview_image>media/preview.png</preview_image></media></theme> - Create a registration.php file for registering your child theme.
12345<?php\Magento\Framework\Component\ComponentRegistrar::register(\Magento\Framework\Component\ComponentRegistrar::THEME,'frontend/{theme-vendor-name}/{parent-theme-name}_child',__DIR__);
123456<?php\Magento\Framework\Component\ComponentRegistrar::register(\Magento\Framework\Component\ComponentRegistrar::THEME,'frontend/Meetanshi/luma_child',__DIR__); - Create composer.json
1234567891011121314151617181920{"name": "{theme-vendor-name}/theme-frontend-{parent-theme-name}-child","description": "N/A","require": {"php": "~5.5.0|~5.6.0|~7.0.0|~7.1.0|~7.2.0|~7.3.0","{parent-theme-vendor-name}/{parent-theme-name}": "100.0.*","magento/framework": "100.0.*"},"type": "magento2-theme","version": "100.0.1","license": ["OSL-3.0","AFL-3.0"],"autoload": {"files": ["registration.php"]}}
1234567891011121314151617181920{"name": "meetanshi/theme-frontend-luma-child","description": "N/A","require": {"php": "~5.5.0|~5.6.0|~7.0.0|~7.1.0|~7.2.0|~7.3.0","magento/luma": "100.0.*","magento/framework": "100.0.*"},"type": "magento2-theme","version": "100.0.1","license": ["OSL-3.0","AFL-3.0"],"autoload": {"files": ["registration.php"]}} - Create web directory inside the child theme with the following empty directories and files. The whole directory structure for the child theme is:
- Provide access/permission for child theme directories and files. Go to child theme directory in the terminal and run this command to give permissions for the child theme directory: chmod -R 777 *Note: If you are working in a local or development server you can provide 777 access for both files and directories. If live server, then you have to give 755 for directory and 644 for files.
- The admin panel shows the created child theme.
- Take a backup of pub/static folder for images, CSS, and js. Also, delete the static folder and run static content deploy.
- Go to the Magento root folder in your terminal and deploy static content using the following command:
1php bin/magento setup:static-content:deploy - The newly created child theme will also deploy in the pub/static folder.
That’s all for creating a Magento 2 child theme! You can now go on with customizing your child theme.
Please feel free to mention your doubts in the Comments section. I’d be happy to help.
Do rate the post with 5 stars if found useful.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
8 Comments
is scandipwa child theme also set like above documentation?
Hello Favaz,
Yes, child theme can be created from any theme.
Thank You
Sanjay –
Great post. I read in official Magento 2 documentation that you should only create a child theme based on Blank… Why is this?
Thanks
Steve
Hello Steve,
No, it is not limited to the Blank theme only. You can create a child theme for any theme.
Thanks.
I created a new theme inheriting from Luma as you explained in the article and applying it to a new page that is still blank, with a 1 column layout and the following occurs: if I do not place the _theme.less and _extends.less files, the page is correct, but if I place these 2 empty files, the page will be unset and still show the login page below. I understood that if the files are empty, the page should look exactly like Luna, right? I checked Debug.log and got this message
[2020-08-05 14:59:29] main.ERROR: variable @ abs-checkout-tooltip-content-position-top is undefined in file [] []
[2020-08-05 14:59:29] main.CRITICAL: variable @ abs-checkout-tooltip-content-position-top is undefined in file [] []
Where did I go wrong?
Hello,
It is the variable error.
abs-checkout-tooltip-content-position-top – This variable is not defined in any class.
Thank you.
Great Blog exactly what people need today, Magento version is upgraded in Magento 2 everyone looking for theme customization so they can make it consistent.
Thank you, Sagar, for the appreciation!