Checked with DAWN from 6.0 up to 8.x
Hi everybody, you can do this with a bit of work. If you want to know how it looks you can visit my âdev websiteâ before you are dooing all these changes below.
https://www.marble-madness.de
Here you can see different header menus and logos if youâre clicking a bit aroundâŚ
So, with this guide here you can have:
-
Different logos on different pages.
-
Having different Menus on different pages.
Lets start, please SAVE your theme before doing all these changesâŚ
First: Open your theme.liquid and replace this code:
{% section 'header' %}
with this code (as an example, read carefully below):
{% if page.url contains 'music' %}
{% section 'header-music' %}
{% elsif page.url contains 'marketing' or page.url contains 'advertising' %}
{% section 'header-advertising' %}
{% elsif page.url contains 'technology' %}
{% section 'header-technology' %}
{% else %}
{% section 'header' %}
{% endif %}
Now please read carfully:
This code checks the name of your page.url. IF you name a Page in your url e.g. something with music, the header-music will be shown. If you e.g. name a Page with advertising or marketing the header-marketing will be used. If the url contains âtechnologyâ the header file âheader-technology.liquidâ will be used.
URL examples:
https://mystore.myshopify.com/pages/something-with-music
the header-music will be shown.
https://mystore.myshopify.com/pages/best-marketing-ever
the header-advertising will be shown.
https://mystore.myshopify.com/pages/mega-technology-things
the header-technology will be shownâŚ
add so on. Note again: This are only examples, feel free to make your changes who fits for you.
So the first thing to remeber is, that your page.url should contain any of the name shown in the example above.
Next step:
-
Go to your code-editor and open âheader.liquidâ. Copy the complete CODE.
-
Add a new section and for our example name it: header-advertising.liquid. Remove the example code after you created the file.
-
Copy the entire code from header.liquid into this new header-advertising.liquid.
-
Save itâŚ
Do the same steps 1-4 with a new file called header-music and if you like the same with header-technology.
This are only examples. You can change the names of your header files and the words from your page.url in the code example as you want.
NOW:
Create one or more pages in shopify OnlineStore/Pages who contains the name you defined in your âifâ code you inserted in theme.liquid and give the pages one of your templates you created.
Now CUSTOMIZE your theme (open the editor) and open one of your pages you created before and which is using one of your templates.
If it works you now can see on the left side on top a âHeaderâ Section and you can choice a new MENU-Logo and a Navigation Menu you created as well.
You can repeat this with every template and any page in the editor IF THE PAGE CONTAINS the valid values you inserted with the codesnipped before in theme.liquid !!! If you dont name the pages in the right way and it does NOT CONTAIN the right values it does not work!!
Last step you have to solve:
If all you did above on desktop it should start working.
This all works very well with DAWN on Desktop, but the different menus can not be opened on smaller screens like iPhone add so on, as the this.url id value is not stored and loaded in the DOM Content loader for smaller screens.
To solve this open your global.js file in code-editor and search for: openMenuDrawer(summaryElement (have a look at line 410-415 or something around).
Replace the complete openMenuDrawer section with the following code:
openMenuDrawer(summaryElement) {
this.borderOffset = this.borderOffset || this.closest('.header-wrapper').classList.contains('header-wrapper--border-bottom') ? 1 : 0;
// check if the header element is present in the DOM
const header = document.getElementById('shopify-section-header');
if (header) {
document.documentElement.style.setProperty('--header-bottom-position', `${parseInt(header.getBoundingClientRect().bottom - this.borderOffset)}px`);
header.classList.add('menu-open');
} else {
// handle case where header element is not present
}
setTimeout(() => {
this.mainDetailsToggle.classList.add('menu-opening');
});
summaryElement.setAttribute('aria-expanded', true);
trapFocus(this.mainDetailsToggle, summaryElement);
document.body.classList.add(`overflow-hidden-${this.dataset.breakpoint}`);
}
This should also solve the problem for the mobile menu.
Hope you get it run, best,
Stefan