How to Create a Custom Theme in Magento
Even though, Magento 2 is in development phase it has already made a lot of buzz in the e-commerce industry because of the new and improved front-end approaches, it is expected to offer. While the front-end improvements seems to make the Magento theme process a lot more efficient, many developers (especially beginners) aren’t still aware of the process of creating a custom theme in Magento 2.
Through this post, I’ll be covering step-by-step process of creating a custom Magento 2 theme. But before that let’s first have an overview of Magento Theme.
Magento Theme – An Overview
A theme helps to create a visual representation of your Magento store, using a combination of the following:
- Custom templates
- CSS/LESS files
Magento application offers two different design themes, namely Luma (also called as a demonstration theme) and Blank (used for custom theme creation). Since we need to create a custom Magento theme, we’ll be using the Magento Blank theme.
In order to create a new theme using Blank, you’ll have to customize it. But, making changes to the default theme will make the changes overwritten, every time the new version of your default files is updated. A viable alternative to this problem is to create a new custom theme that inherits the functionality from the default or any existing theme.
Put it simply, we’ll create a custom child theme that inherits existing theme’s functionality. Doing so, will help you going through the hassle of creating a new standalone theme from the ground up. So, instead of copying extensive set of files and modifying them, you will only need to override and extend existing files within the parent theme.
Let’s now begin discussing the steps involved in creating a new Magento theme (i.e. the one one by one.
Understanding Theme Creation Process
In this section, we will be covering about creating files that would help in theme creation. In addition, we’ll also have a glimpse of the process of adding a logo to the theme or how we can configure images.
Step 1 – Create a Theme Directory
The very first step, you need to perform when creating a custom theme requires you to create your theme directory structure. For doing so, follow below mentioned key points:
- Access and open up your Magento install admin backend, and then move to dir>/app/design/frontend.
- Most of the e-stores offers products of different vendors, and so it’s important to have a separate vendor directory, where all products offered by the vendors are listed. So, your next step is to create a new directory with the name similar to your vendor name: /app/design/frontend/<Vendor>.
In case, you’re using any built-in Magento theme, then you need to refer to the directory: app/design/frontend/Magento
- Now that you’ve created the vendor directory, create another directory with the name similar to that of your theme under the vendor directory as shown below.
Step 2 – Understanding Theme Declaration
Once you’ve finished creating the directory structure of your theme, you’ll have to create theme.xml to define your theme layout. The xml file must contain at least the child theme name and the parent theme name. All the updates made to your theme layout will be stored in this file.
There are two tasks that your theme layout needs to perform.
- First add or copy contents from the current theme.xml to your theme directory app/design/frontend/<Vendor>/<theme>
- Secondly, to make your theme visible, you need to configure it. For this purpose, use the following example:
<theme xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”../../../../../lib/internal/Magento/Framework/Config/etc/theme.xsd”>
<title>New theme</title> <!– your theme’s name –>
<parent>Magento/blank</parent> <!– the parent theme, in case your theme inherits from an existing theme –>
<preview_image>media/preview.jpg</preview_image> <!– the path to your theme’s preview image –>
In order to make sure that your theme is recognized by the Magento application, get logged-in in to the Magento admin panel and check whether you can see the theme in the grid under Content-> Design -> Themes.
Step 4 – Configure Images (Changing Size of the Product Images)
When uploading the product images, if its size exceeds than the ones of the default theme, you’ll have to add a view.xml file. This file contains configuration details of the product image sizes that are displayed on the storefront. Let’s now see the steps you need to follow for configuring the images:
- Log-in to your Magento server, however, you’ll need to access the server as a user having a certain set of permissions. You must have permissions to create directories as well as files in the directory of the Magento installation.
- In your theme folder, create the etc directory.
- Next, copy the view.xml file from your existing theme’s “etc directory” (let’s say, for example, from the Blank theme) to your custom theme’s newly created etc directory.
- Lastly, you need to configure all of the product image sizes used on your store front-end in view.xml. For example, you can choose to portray the product images in the product category grid view as square, by assigning it a size of 250 x 250 px. Let’s have a glimpse of how the image configuration would look like:
Step 5 – Create Directories for Your Theme’s Static Files
Note: All the general theme static files should be stored in the …<theme>/web/images, for example, the logo of your theme needs to be stored in …<theme>/web/images. There’s a greater possibility that your theme will include some module-specific files. These files are stored in the sub-directories like …/<theme>/<Namespace_Module>/web/css and related sub-directories. However, this is a whole new topic of discussion. So, for now we will skip this topic.
Applying and Configuring Your Theme in Magento
This section will let you know how you can apply your theme to the Magento storefront. For doing so, simply follow the below listed steps:
Step 1 – Open up your Magento install admin panel and navigate to CONTENT-> Design-> Themes. Make certain that you can see your theme in the given theme list.
Step 2 – From your admin panel visit Stores -> Configuration -> Design.
Step 3 – From the “Scope” drop-down field, choose the store view to which you would like to apply your theme.
Step 4 – Next, from the “Design” Theme tab, choose the theme you’ve just created listed in the Design Theme drop-down.
Step 5 – Lastly, click on the “Save Config” option to apply the changes you have made so far. And once it’s done, make sure to reload the pages of your storefront.
Note: In case, caching is enabled in your Magento back end, it’s important to clear the cache or else you may not be able to see the changes you’ve just applied.
Hope that reading this tutorial will serve as a basic guide that will help you understand the process of creating a custom theme in Magento 2.
Author Bio :
Isabella Morris is currently employed with a renowned custom Magento development company and is also engaged in writing informative articles on best tools and tricks for Magento development. Her write-ups have proved beneficial for a wider group of Magento developers across the globe.
You may also like:
- Bigcommerce vs Magento: Detailed Comparison
- Why custom 404 pages are important (You should have one too)
- Designer's Guide to Custom Typography
- How to Develop a Custom Mobile App in 3 Simple Steps
- Next Day Flyers Giveaway - 100 CUSTOM Post Cards! Do not miss.
- Custom Sticker Giveaway by Sticker Mule
- Web Design: Is it Necessary to Know How to Create Traditional Art First?
- How to Create a Website for Your Business
- 21 Ideas to Create Engaging Web Designs
- How To Create a Green Grunge Web Layout
Subscribe to our RSS feed!
Popular on Web Design Dev:
- Free Wix Website Templates
- 20+ Portfolio Website Templates for Architects
- 20+ Portfolio Website Templates for Artists
- Creative Resume Templates for Web Designers
- Web Safe Fonts with CSS
- Best Free Tumblr Themes
- 20+ Free HTML Templates
- Professional Free Bootstrap Themes
- Best Shopify Themes for High Conversions
- 20+ Events Production Website Templates