cancel
Showing results for 
Search instead for 
Did you mean: 

How can I edit top navigation menu?

How can I edit top navigation menu?

How can I edit top navigation menu? Is it possible to add new menus at top? And is it possible to delete some menus from top?

5 REPLIES

Re: How can I edit top navigation menu?

If you are talking about the Catalog Navigation this link will be helpful for you:

https://docs.magento.com/m2/ce/user_guide/catalog/navigation-top.html

 

If you are taking about header links you can add new links by create below files:

app/design/frontend/vendor/theme/Magento_Theme/layout/default.xml

 

<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="custom-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="true">custom link</argument>
                    <argument name="path" xsi:type="string" translate="true">customlink</argument>
                </arguments>
                </block>
            </referenceBlock>

            </body>
        </page>

If you want to remove any link:

Add default.xml file in this path

app/design/frontend/vendor/theme/Magento_Theme/layout/default.xml

 

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
            <body>

                    <referenceBlock name="register-link" remove="true" />           <!--for Create Account Link-->
                    <referenceBlock name="authorization-link" remove="true" />      <!--for Sign In Link  -->
                    <referenceBlock name="wish-list-link" remove="true" />          <!--for WishList Link-->
                    <referenceBlock name="my-account-link" remove="true" />         <!--for My Account Link-->

            </body>
        </page>

Hope it will be helpful for you

Re: How can I edit top navigation menu?

"app/design/frontend/vendor/theme/Magento_Theme/layout/default.xml"

 

should it be "app/design/frontend/Magento/theme-frontend-luma/Magento_Theme/layout/default.xml" ? (if i want to customize luma theme)

Re: How can I edit top navigation menu?

Yes, you can edit this and then flush cache and check if it works for you.

Or if you have a custom module you can also place default.xml in your custom module and update it the file path will be something like this:

app\code\MyModule\Custommodule\view\frontend\layout\default.xml

in this file you can place the same code which I have shared in my previous answer.

Re: How can I edit top navigation menu?

"app/design/frontend/vendor/theme/Magento_Theme/layout/default.xml" what is vendor and theme here?

 

Can you post example code to do this with custom module?

Re: How can I edit top navigation menu?

Here vendor is Vendor's Name i.e Company's Name who is creating this custom theme and "theme" keyword is representing the name of Theme.

If you want you can also create your own theme under app/design/frontend/companyname/themename/....

 

If you have already created custom module under app/code then you can place the default.xml, in my case the path is:


app\code\Aman\Custom\view\frontend\layout\default.xml

 

and the code I have added is:

<?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="header.links">
         <block class="Magento\Framework\View\Element\Html\Link" name="custom-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>
      <referenceBlock name="register-link" remove="true" />
    </body>

If you want to learn how to create custom module in Magento 2 you can have a look on this link:

http://inchoo.net/magento-2/how-to-create-a-basic-module-in-magento-2/