Categories: Magento

How to create a theme in Magento 2

Creating a custom theme in Magento 2 allows you to modify the visual appearance and layout of your store. Here’s a step-by-step guide on how to create a theme in Magento 2:

Step 1: Set up the theme directory structure
In your Magento installation, navigate to the `app/design/frontend` directory. Inside the `frontend` directory, create a new directory with the following structure: `VendorName/ThemeName`. Replace `VendorName` with your desired vendor name and `ThemeName` with the name of your theme. This will be the base directory for your theme.

Step 2: Create the theme configuration file
Inside the `ThemeName` directory, create a new directory called `etc`. Inside the `etc` directory, create a file named `theme.xml`. This file will define your theme and its parent theme (if applicable). Add the following content to the `theme.xml` file:

“`xml
<theme xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:Config/etc/theme.xsd”>
<title>Your Theme Title</title>
<parent>Magento/blank</parent>
</theme>
“`

Replace `Your Theme Title` with the desired title for your theme. The `parent` node specifies the parent theme for your theme. In this example, we have used `Magento/blank` as the parent theme, which is a default blank theme provided by Magento.

Step 3: Create the registration.php file
Inside the `ThemeName` directory, create a file named `registration.php`. This file is used to register your theme. Add the following content to the `registration.php` file:

“`php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
‘frontend/VendorName/ThemeName’,
__DIR__
);
“`

Replace `VendorName` and `ThemeName` with your actual vendor name and theme name.

Step 4: Create the theme’s main layout file
Inside the `ThemeName` directory, create a new directory called `Magento_Theme`. Inside the `Magento_Theme` directory, create another directory called `layout`. Inside the `layout` directory, create a file named `default.xml`. This file is the main layout file for your theme. You can add layout instructions and structure to this file based on your design requirements.

Step 5: Create the theme’s default template files
Inside the `ThemeName` directory, create a new directory called `Magento_Theme`. Inside the `Magento_Theme` directory, create a directory named `templates`. Inside the `templates` directory, you can create template files (`.phtml`) that correspond to the components of your theme.

Step 6: Set the theme in Magento configuration
Access the Magento Admin Panel and navigate to “Content” > “Configuration”. Select the desired store view and click on “Edit” in the Action column.

Under the “Design Theme” section, select your newly created theme from the “Applied Theme” dropdown menu. Save the configuration.

Step 7: Deploy the static content
In the command line, navigate to the root directory of your Magento installation.

Run the following command to deploy the static content:

“`
php bin/magento setup:static-content:deploy
“`

This command generates the static files required for your custom theme.

Step 8: Verify and customize your theme
Visit your Magento store frontend to verify that your custom theme is applied. You can start customizing your theme by modifying the layout files, template files, CSS files, and other resources according to your design requirements.

Congratulations! You have successfully created a custom theme in Magento 2. You can continue to customise and enhance your theme by adding more styles, layouts, and components to create a unique visual experience for your store.

Article by: Web Designers Near Me | Author: Joseph Cozens – Senior Website Designer

With over 25 years experience, Joseph started as the leased line manager for an ISP in the 1990’s and built websites for the support team internally, but was often asked by corporate business customers if we could provide a website for their company. So in 1998 with people looking for website designers near me, he started the web design company building websites part time, and in 1999 started building websites full time. In the early 2000’s we decided to call ourselves DesignsOnline.co.uk Joseph built one of the first online medical schools allowing doctors worldwide to enrol and pay for medical statistics training via the internet… Joseph used to build bespoke content management systems for companies who needed to regularly update their websites and for bespoke ecommerce websites which were hand coded at the time.

Today Joseph develops and builds top level professional websites without the needlessly high price tag.
You can contact Joseph directly via WhatsApp on 07944062954.

Web Designers Near Me

With over 25 years experience, Joseph started as the leased line manager for an ISP in the 1990's and built websites for the support team internally, but was often asked by corporate business customers if we could provide a website for their company. So in 1998 with people looking for website designers near me, he started the web design company building websites part time, and in 1999 started building websites full time. In the early 2000's Joseph built one of the first online medical schools allow doctors worldwide to enrol and pay for medical statistics training via the internet.