How can I add a block to the magento 2 luma header like in this image? I'm using M2.2 and app/design/frontend/magento directory is empty (i see that referenced a lot).
Magento 2 Luma Theme – How to Add Block to Header
luma-thememagento2
Related Solutions
When creating any new theme or module you need to define registration.php file at root of your module or theme folder.
Always use theme name in lowercase, Because Magento used this standard for theme name declaration.
You haven't any problem for keep Theme name in camelcase but use standard way is much appreciated.
You have to define registration.php file inside Magento_Theme folder, its in wrong place.
Correct diagram of theme structure will be below,
magento2
|_ app
|_ design
|_ frontend
|_ Custom
|_theme
|_Magento_Theme
|_templates
|_root.phtml - Copy of Luma
|_registration.php
|_theme.xml
Your path for registration.php is app\design\frontend\Custom\theme\registration.php
registration.php file :
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::THEME,
'frontend/Custom/theme',
__DIR__
);
your theme.xml file path will be,
app\design\frontend\Custom\theme\theme.xml
theme.xml file :
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
<title>Custom Theme</title>
<parent>Magento/luma</parent>
<media>
<preview_image>media/preview.jpg</preview_image>
</media>
</theme>
After all setup is completed, don't forget to run deploy command for the theme,
php bin/magento setup:static-content:deploy
Check inside your admin panel, Content -> Design -> Configuration
for set your custom theme.
Remove cache and check in the frontend.
Customizing Header in extended LUMA Theme
Adding a <DIV />` around your logo and giving styles:
Edit
logo.phtml
and put a Div around the logo. Assign a class to the DIV and define styles to this class in your CSS files.app/design/frontend/vendorname/themename/Magento_Theme/templates/html/header/logo.phtml
Use
_extend.less
for adding custom stylesapp/design/frontend/vendorname/themename/Magento_Theme/web/css/source/_extend.less
Edit your search box in your extended module, extend if not extended. Add a DIV around it and assign our class and define styles in
_extend.less
app/design/frontend/vendorname/themename/Magento_Search/templates/form.mini.phtml
The same method as above you can use for Navigation at the below path in
sections.phtml
app/design/frontend/vendorname/themename/Magento_Theme/templates/html/header/sections.phtml
I hope this will help you
If you need to move element in top bar then check my answer on this question How to move correctly block-search and minicart to panel wrapper? Magento 2
Run upgrade/deploy/cache
command to see the CSS changes if you are using _extend.less
for custom styling
Best Answer
Add below code at after
top.search
referenceContainer:Note: Need to change block id
topPromo
with your block Id and need some CSS for positioning.