How to add custom link (on custom module, not at theme) at header in magento 2

1 Answer 1


Create default.xml file in your custom module.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceBlock name="header.links">
            <block class="Vendor_name\Module_name\Block\Link" name="some_link" before="-">
                    <argument name="label" xsi:type="string" translate="true">Custom link</argument>
                    <argument name="path" xsi:type="string">test</argument>

enter image description here

it will display in header links


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