How to Create Child Theme in Magento 2

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.

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.

  1. Create a child theme folder named as {parent-theme-name}_child in the following folder path.
    Name your child theme related to the parent theme. It can be anything that is developer friendly!
  2. Create file theme.xml inside the child theme to specify the parent theme inherited by the child theme
    Example:
  3. Create a registration.php file for registering your child theme.
    {theme-vendor-name} should exactly match the vendor folder name. Vendor name should be capitalized. Ex: Meetanshi
  4. Create composer.json
    Example:
  5. Create web directory inside the child theme with the following empty directories and files. The whole directory structure for the child theme is:

    Magento-2-Create-Child-Theme-File-Path-Meetanshi

  6. 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:sudo 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.
  7. The admin panel shows the created child theme.
    1. Login to admin panel
    2. Go to Content > Themes1_theme
    3. Select child theme in admin configuration
    4. Go to Content > Design > Configuration.2_design configuration
    5. Select the child theme3_select child theme
    6. Save
    7. Flush the cache
  8. Take a backup of pub/static folder for images, CSS, and js. Also, delete the static folder and run static content deploy.
  9. Go to the Magento root folder in your terminal and deploy static content using the following command:

  10. 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.

5
(based on 14 Reviews)

Sanjay is a co-founder at Meetanshi. He is a certified Magento developer who loves creating Magento E-commerce solutions. When he is not engrossed with anything related to Magento, he loves to play cricket.

Leave a Reply