0

I have created a custom link using default.xml and moved it inside the top.links reference block. This is my code

<referenceBlock name="top.links">
    <block class="Magento\Framework\View\Element\Html\Link" name="custom-top-link-blog">
        <arguments>
            <argument name="label" xsi:type="string" translate="true">Blog</argument>
            <argument name="path" xsi:type="string">#</argument>
        </arguments>
    </block>
</referenceBlock>

I have also made some changes to top.links block.

<move element="register-link" destination="top.links"/>
<move element="top.links" destination="header-wrapper" after="minicart"/>

This is what I have achieved. Plz check the screenshot. enter image description here

Now I need to move my custom link "Blog" before My Account that is in the first position. Screenshot where I need it. enter image description here

How I can achieve this. I have tried adding before="-" in this line

<block class="Magento\Framework\View\Element\Html\Link" name="custom-top-link-blog" before="-">

but it did not worked. Plz suggest how I can achieve this.

Update: I have tried a solution according to the suggestion in comment but it did not worked. I found the block name for My Account section. I found it inside the module-customer default.xml file. This was the code.

<referenceBlock name="top.links">
        <block class="Magento\Customer\Block\Account\Link" name="my-account-link">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">My Account</argument>
            </arguments>
        </block>
        <block class="Magento\Customer\Block\Account\RegisterLink" name="register-link">
            <arguments>
                <argument name="label" xsi:type="string" translate="true">Sign up</argument>
            </arguments>
        </block>
        <block class="Magento\Customer\Block\Account\AuthorizationLink" name="authorization-link"
               template="Magento_Customer::account/link/authorization.phtml"/>
    </referenceBlock>

Then I used this block name in my custom theme default.xml file to change the position of Blog but it did not worked. This was the code that I added in default.xml file.

<move element="custom-top-link-blog" destination="top.links" before="my-account-link"/>

Plz let me know a solution to achieve this as I am stuck in this.

3
  • You just need to find "My account" reference block name in your theme's file.And after that you need to add that reference block name in before="My account reference block". It should be work.
    – ZealousWeb
    Jun 23, 2021 at 4:17
  • @ZealousWeb I have tried a solution according to your suggestion but it did not worked, plz have a look. Jun 23, 2021 at 15:11
  • please add this and check - <move element="custom-top-link-blog" destination="top.links" before=''-"/>
    – ZealousWeb
    Jun 24, 2021 at 9:50

1 Answer 1

0

I don't know why changing the position of my custom link did not work, but then I solved this by removing my custom link from top.links section and adding it to header-wrapper and then assigning the position.

<referenceContainer name="header-wrapper">
    <block class="Magento\Framework\View\Element\Html\Link" name="custom-top-link-blog" template="Magento_Theme::blog-link.phtml" />
</referenceContainer>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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