2

I am trying to add a custom header in Magento 2. I am creating my custom theme and add custom header page customeheader.phtml but header is not show.

this is my code

2

default.xml

<referenceContainer name="page.wrapper">
     <block class="Magento\Framework\View\Element\Template" 
            name="Custom_header" 
            template="Magento_Theme::html/customheader.phtml" 
            before="main.content"/> </referenceContainer> <move element="navigation.sections" destination="Custom_header"/> <move element="top.search" destination="Custom_header"/> <move element="minicart" destination="Custom_header"/> <move element="currency" destination="Custom_header"/> <move element="logo" destination="Custom_header"/> <move element="skip_to_content" destination="Custom_header"/>
1

If you want to add custom header then you just add this code into Magento_Theme / layout / default.xml

<referenceBlock name="header.container" remove="true" />
<referenceContainer name="page.wrapper">
    <block  class="Magento\Framework\View\Element\Template" name="top.header" template="Magento_Theme::customheader.phtml" before="header.container"/>
</referenceContainer>      
<move element="minicart" destination="top.header" />

And create customheader.phtml in Magento_Theme / templates / customheader.phtml

Hope it's help you !

0

Apart from above answers

I would like to add parent entities <page><body> for the default.xml file. This is basically for the newcomers like me, because without this page and body our file will not reflected on the frontend.

here is my update default.xml file

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="header.container" remove="true" />
        <referenceContainer name="page.wrapper">
            <block  class="Magento\Framework\View\Element\Template" name="top.header" template="Magento_Theme::customheader.phtml" before="header.container"/>
        </referenceContainer>      
        <move element="minicart" destination="top.header" />
    </body>
</page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.