0

I have a top. links in default.xml in my theme, I need to add the custom link above My Account, but the link is always at the bottom, how I can move to the top if sortOrder not working?

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="logo">
            <arguments>
                <argument name="logo_file" xsi:type="string">images/[email protected]</argument>
                <argument name="logo_width" xsi:type="number">300</argument>
                <argument name="logo_alt" xsi:type="string">Auto Show Fire</argument>
            </arguments>
        </referenceBlock>
        
         <referenceContainer name="header.container" remove="true">
            <referenceContainer name="header.panel.wrapper" remove="true" />
            <referenceContainer name="header.panel" remove="true" />
            <referenceBlock name="top.search" remove="true"/>
        </referenceContainer>

        <referenceContainer name="header-wrapper">
            <referenceBlock name="navigation.sections" remove="true" />
        </referenceContainer>

        <move element="top.links" destination="custom_header"/>

        <referenceBlock name="top.links">

            <block class="Magento\Framework\View\Element\Html\Link" name="custom-top-link">
                <arguments>
                    <argument name="sortOrder" xsi:type="number">1000</argument>
                    <argument name="label" xsi:type="string" translate="true">Custom Top Link</argument>
                    <argument name="path" xsi:type="string">*/*/*</argument>
                </arguments>
            </block>

            
            <block class="Magento\Customer\Block\Account\Link" name="help-link" before="authorization-link">
                <arguments>
                    <argument name="path" xsi:type="string">contacts</argument>
                    <argument name="label" xsi:type="string">Help</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

<argument name="sortOrder" xsi:type="number">1000</argument> - don't work. Any Idea how I can move this custom link at the top so that it is always located at the top of the menu.

2

2 Answers 2

1

Try this,

create default.xml file in app/code/Vendorname/ModuleName/view/frontend/layout directory.

<?xml version="1.0"?>
<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="my-top-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="true">My Top Link</argument>
                    <argument name="path" xsi:type="string">*/*/*</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

top.links: To add custom link in Top links.

ss :- https://i.stack.imgur.com/zybl0.png

flush the layout cache. Thanks!

0

Try this code.

File: app/design/frontend/Vendor/Theme/Magento_Theme/layout/default.xml

<referenceBlock name="top.links">

            <block class="Magento\Framework\View\Element\Html\Link" name="custom-top-link" before="-">
                <arguments>
                    <argument name="sortOrder" xsi:type="number">1000</argument>
                    <argument name="label" xsi:type="string" translate="true">Custom Top Link</argument>
                    <argument name="path" xsi:type="string">*/*/*</argument>
                </arguments>
            </block>
</referenceBlock>

Your Answer

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

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