Your own free Magento theme: a Luma child theme per store view
A Luma child theme with your own logo, colours, font and one template, made in eight small files, registered and deployed in production mode, then used on one store view while another store view keeps a different theme. Free, no licence key, no Node.js.
Downloads
Every file of the theme from the video. Put them in app/design/frontend/MageBooster/demo/ with the same sub-folders (the path is under each name).
What a theme is
A Magento theme is a set of layouts, templates, styles and images, and themes inherit from each other:
| Theme | What it is |
|---|---|
Magento/blank | The base theme: plain, meant to build on. |
Magento/luma | A child of Blank: the default look of Magento 2. |
MageBooster/demo | Our child of Luma: only the files we change. |
Fallback: for every file, Magento looks in MageBooster/demo first, then Magento/luma, then Magento/blank, then the module. The first file found wins. So a child theme stays small, and Luma updates still reach it.
The theme folder
theme.xml
registration.php
composer.json
etc/view.xml
web/css/source/_extend.less
web/images/logo.svg
Magento_Theme/layout/default.xml
Magento_Theme/templates/html/copyright.phtml
# as the magento user, in the Magento folder
cd /var/www/magento
mkdir -p app/design/frontend/MageBooster/demo && cd app/design/frontend/MageBooster/demo
mkdir -p etc web/css/source web/images Magento_Theme/layout Magento_Theme/templates/html
# ... create the files below, then the image sizes: copy Luma's view.xml and change one size
cp /var/www/magento/vendor/magento/theme-frontend-luma/etc/view.xml etc/
sed -i '/"category_page_grid"/,/<\/image>/{s/<width>240/<width>270/;s/<height>300/<height>338/}' etc/view.xml
grep -A3 '"category_page_grid"' etc/view.xml
The files
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>MageBooster demo</title>
<parent>Magento/luma</parent>
</theme>
theme.xml: The title in the admin and the parent theme.
<?php use Magento\Framework\Component\ComponentRegistrar; ComponentRegistrar::register(ComponentRegistrar::THEME, 'frontend/MageBooster/demo', __DIR__);
registration.php: Registers the folder as the theme frontend/MageBooster/demo.
{
"name": "magebooster/theme-frontend-demo",
"description": "MageBooster demo: a Luma child theme",
"type": "magento2-theme",
"license": "MIT",
"require": { "magento/theme-frontend-luma": "*" },
"autoload": { "files": ["registration.php"] }
}
composer.json: Only used when you ship the theme as a Composer package; harmless otherwise.
// MageBooster demo: brand colours and a font, on top of Luma
@mb-dark: #160040;
@mb-accent: #79018C;
@font-family-name__base: system-ui;
& when (@media-common = true) {
.page-wrapper .page-header .panel.wrapper, .page-wrapper .page-footer, .copyright { background: @mb-dark; color: #fff; }
.panel.header .header.links a, .page-footer a, .page-footer .switcher .label { color: #fff !important; }
.action.primary { background: @mb-accent; border-color: @mb-accent; }
.action.primary:hover, .action.primary:focus { background: @mb-dark; border-color: @mb-dark; }
a, .breadcrumbs a, .product-item-link { color: @mb-accent; }
}
.media-width(@extremum, @break) when (@extremum = 'min') and (@break = @screen__m) {
.page-wrapper .nav-sections, .navigation { background: @mb-accent; }
.navigation .level0 > .level-top { color: #fff !important; border-color: #fff !important; }
}
web/css/source/_extend.less: Added on top of Luma's styles. system-ui is the visitor's own system font: no font files, no request to Google.
<svg xmlns="http://www.w3.org/2000/svg" width="260" height="48" viewBox="0 0 260 48">
<style>text { font: 700 20px system-ui, Arial, sans-serif; }</style>
<rect width="48" height="48" rx="11" fill="#79018C"/>
<text x="24" y="31" text-anchor="middle" fill="#fff">MB</text>
<text x="60" y="31" fill="#160040">MageBooster demo</text>
</svg>
web/images/logo.svg: Same path as Luma's logo, so fallback picks ours.
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="logo">
<arguments>
<argument name="logo_width" xsi:type="number">260</argument>
<argument name="logo_height" xsi:type="number">48</argument>
</arguments>
</referenceBlock>
</body>
</page>
Magento_Theme/layout/default.xml: The logo's width and height, so the header does not jump while the page loads.
<?php /** @var \Magento\Framework\Escaper $escaper */ ?>
<small class="copyright">
<span>© <?= date('Y') ?> MageBooster demo · <?= $escaper->escapeHtml(__('Built on a Luma child theme')) ?></span>
</small>
Magento_Theme/templates/html/copyright.phtml: Overrides the footer copyright template of the Magento_Theme module.
etc/view.xml holds the image sizes. A child theme's view.xml replaces the parent's (it is not merged), so copy Luma's file and change what you need, as in the commands above (the category grid images become 270 × 338).
Registering and deploying
setup:upgrade registers the theme. No PHP classes were added, so --keep-generated keeps the compiled code. In production mode the styles come from pub/static: deploy the theme. Luma's LESS is compiled by PHP during the deploy, so no Node.js is needed.
cd /var/www/magento bin/magento setup:upgrade --keep-generated bin/magento setup:static-content:deploy -f --area frontend --theme MageBooster/demo en_US # after assigning the theme in Content > Design > Configuration bin/magento cache:flush
A theme per store view
- Content › Design › Configuration: one row for Global, one per website, one per store view. A theme set on a row is inherited by the rows below it, unless they have their own.
- Default Store View › Edit › Applied Theme: MageBooster demo. Other Settings › HTML Head › Favicon Icon › Upload (JPG, GIF, PNG, ICO or APNG). Save Configuration.
- German › Edit › Applied Theme: Magento Blank. Header › Logo Image › Upload (JPG, GIF or PNG), Logo Attribute Width 260, Height 48. A logo uploaded here wins over the theme's
logo.svg. Save Configuration. - Flush the cache.
The same from the command line:
# the same assignment from the command line (theme ids: SELECT theme_id, theme_path FROM theme;) bin/magento config:set --scope=stores --scope-code=default design/theme/theme_id 4 bin/magento config:set --scope=stores --scope-code=de design/theme/theme_id 1 bin/magento indexer:reindex design_config_grid bin/magento cache:flush
The result
| Default Store View | German | |
|---|---|---|
| Theme | MageBooster demo (Luma child) | Magento Blank |
| Logo | web/images/logo.svg from the theme | uploaded in the admin |
| Colours and font | dark purple bar and footer, purple menu, buttons and links, system-ui | Blank defaults |
| Favicon | uploaded in the admin | Magento default |
| Footer copyright | our template | the standard one |
And Hyvä?
Hyvä is a popular, faster frontend theme. It is free too, but it needs a (free) key from hyva.io and some extensions need compatibility modules. It gets its own lesson later in this course.
Troubleshooting
| Symptom | Cause and fix |
|---|---|
| The theme is not in the Applied Theme list | registration.php or theme.xml has a typo, or setup:upgrade was not run. |
| Changes to a theme file do not show | Old copies in pub/static and var/view_preprocessed: remove them and deploy again (below), then flush the cache. |
| The page has no styles at all | The theme was not deployed for that locale. Deploy it with the store view's locale (here en_US). |
| Product images lost their sizes | A partial etc/view.xml: it replaces Luma's. Start from a full copy of Luma's file. |
| The logo upload is refused | The Logo Image field takes JPG, GIF or PNG only. An SVG logo goes into the theme as web/images/logo.svg. |
# changed a theme file later? remove the old copies first, otherwise they stay cd /var/www/magento rm -rf pub/static/frontend/MageBooster var/view_preprocessed/pub/static/frontend/MageBooster bin/magento setup:static-content:deploy -f --area frontend --theme MageBooster/demo en_US bin/magento cache:flush
Next lesson
Lesson 10: products. A simple and a configurable product, values per store view, and SEO.
▶ Watch every MageBooster lesson on YouTube: all lessons in order · subscribe to the channel
