0

I want to add header links in magento Blank Theme

Default.xml

<referenceBlock name="top.links">
      <block class="Magento\Framework\View\Element\Html\Link" name="new.link" after="register-link">
        <arguments>
            <argument name="label" xsi:type="string" translate="false">New Link</argument>
            <argument name="path" xsi:type="string" translate="false">newlink</argument>
        </arguments>
      </block>
 </referenceBlock>

i have added top.links because its blank theme. after that i ran all CLI command. but link is not displaying on frontend.

1

Add top link with frontend theme:

  1. app/design/frontend/[VendorName]/[themename]/registration.php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::THEME,
  'frontend/[VendorName]/[themename]',
    __DIR__
);
  1. app/design/frontend/[VendorName]/[themename]/theme.xml
<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
    <title>Theme Title</title>
    <parent>[VendorName]/[themename]</parent> <!-- Magento/blank OR Magento/luma -->
</theme>
  1. app/design/frontend/[VendorName]/[themename]/Magento_Theme/layout/default.xml

If you've extended Luma Theme:

<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.links">
            <block class="Magento\Framework\View\Element\Html\Link" name="header-new-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="true">New Link</argument>
                    <argument name="path" xsi:type="string" translate="true">new-link</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

If you've extended Blank Theme:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="top.links">
            <block class="Magento\Framework\View\Element\Html\Link" name="header-new-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="true">New Link</argument>
                    <argument name="path" xsi:type="string" translate="true">new-link</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>
  1. Magento CLI
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
php bin/magento cache:flush

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.