In this article, we will explain How to create a child theme in Magento 2.
Before continuing to the stages, let’s first clarify what a theme in Magento 2 is and why you need to develop a child theme in Magento 2.
Before we start We called our child theme luma_child and placed it in Dolphin(Vendor Name) folder.
Now, we will start to create a child theme step-by-step.
Step 1: Create a child theme folder named {parent-theme-name}_child at app/design/frontend/{theme-vendor-name}/{parent-theme-name}_child
Example: app/design/frontend/Dolphin/luma_child
Step 2: Now you should create a theme.xml file at app/design/frontend/Dolphin/luma_child/ for the specify the parent theme inherited by the child theme and add the below-mentioned code:
<!-- /** * Created By: Dolphin Web Solution Pvt. Ltd. */ --> <theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd"> <title>Dolphin Luma Child</title> <!-- your Child theme name --> <parent>Magento/luma</parent> <!-- parent-theme-vendor-name/parent-theme-name --> <media> <preview_image>media/preview.png</preview_image> <!-- the path to your theme's preview image --> </media> </theme>
Note: Make sure you added preview.png file at app/design/frontend/Dolphin/luma_child/media/ directory location.
Step 3: Create a registration.php file at app/design/frontend/Dolphin/luma_child/ path for registering your child theme and add the below-mentioned code:
<?php /** * Created By: Dolphin Web Solution Pvt. Ltd. */ \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::THEME, 'frontend/Dolphin/luma_child', /* {theme-vendor-name}/{parent-theme-name}_child */ __DIR__ );
Step 4: Create a web directory with the following empty directories and files inside the child theme. The child theme’s entire folder structure and files are following:
app/design/frontend/Dolphin/ ├── luma_child/ │ ├── media/ │ │ ├── preview.png │ ├── web/ │ │ ├─css/ │ │ │ ├─source/ │ │ │ ├─_extend.less │ │ ├─fonts/ │ │ ├─images/ │ │ ├─js/ │ ├── registration.php │ ├── theme.xml
Step 5: Now, Just run below Magento commands
php bin/magento setup:upgrade php bin/magento setup:static-content:deploy –f php bin/magento cache:clean
Step 6: Applying theme in the admin panel and check whether your theme is added to the theme list or not.
Step 7: Now click edit and select your child theme in admin configuration
Step 8: Select your child theme in the Applied Theme dropdown field.
Now, click on the save configuration button from the top right.
That’s it! Now you can continue to modify your child theme.
I hope this technical blog will help you to find what you were looking for.
If you have any further questions about Magento 2 theme development or if need any help from our Magento 2 expert, contact us now for a free consultation.
Bookmark it for your future reference. Do comment below if you have any other questions.
P.S. Do share this note with your team.
Click one of our contacts below to chat on WhatsApp