1

I'm trying to add a custom CMS page link (home) to the navigation menu which was successful using the following code in layout/default.xml

    <referenceContainer name="catalog.topnav">
      <block class="Magento\Cms\Block\Block" name="home-link" before="-">
        <arguments>
          <argument name="block_id" xsi:type="string">home-link</argument>
        </arguments>
      </block>
    </referenceContainer>

However - the link is simply added to the end of the menu. I would like, if possible to be able to display this as the first link.

Can anyone help please?

2

One way to do this is to place the link in store.menu instead of catalog.topnav.

<referenceBlock name="store.menu">
    <block class="Magento\Cms\Block\Block" name="home-link" before="-">
        <arguments>
            <argument name="block_id" xsi:type="string">home-link</argument>
        </arguments>
    </block>
</referenceBlock>

One of the issues here is the link wont be inline with the other links in the menu, but here are some styles i played with to get it looking close.

display: block;
float: left;
z-index: 9;
margin: 15px 20px;
position: relative;
font-weight: 900;
color: #575757;

I did this in the browser, so you might need to play with it a little more depending on the theme you are using and the responsive needs you have.

enter image description here

  • Unfortunately that just throws the link to the very far left of the screen. Appreciate the effort though! Thanks – Gazweb Mar 8 '18 at 22:00
  • Does the link end up in the navigation container? The code i'm using is based on the Blank theme, so you might have some styles in the nav that i can't account for. If you post them here, i'm sure we could figure it out. – circlesix Mar 8 '18 at 22:04

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.