Add a non-category links to the navigation menu in Magento 2

Magewallet | Magento 2 Extensions, Themes & Solutions

Add a non-category links to the navigation menu in Magento 2

As we know Magento 2 does not include features like adding extra(home, blog) links to main navigation menu. In this blog post we will discuss how to add non category links to navigation menu in Magento 2. In this we will use Magento 2 Observer page_block_html_topmenu_gethtml_before to add new link to menu.

Lets consider module with Namespace is Magewallet and Module Name is NavLinks. Lets list down all the files require for this extension.

– registration.php
– composer.json
– etc/module.xml
– etc/frontend/events.xml
– Observer/Topmenu.php

First we will create registration file at app/code/Magewallet/NavLinks/registration.php file

Now, create a composer.json file in app/code/Magewallet/NavLinks/ folder as per below.

now create module.xml file in app/code/Magewallet/NavLinks/etc

now create events.xml file in app/code/Magewallet/NavLinks/etc/frontend

Now we will create Observer/Topmenu.php file.

Now run upgrade command php bin/magento setup:upgrade to install the module. Clear Magento 2 cache.

You have known all the steps to add new links to navigation menu of Magento 2. if you have any questions about this post, please ask them in comments.

Enjoy Magento 2! Enjoy Magewallet!!

admin

2 Comments

Pit Wegner

34 mins ago

How can I make the links dynamic so they can change depending on the store view? And how can I add multiple links?

Amy Ling

34 mins ago

Thanks for this tutorial. First off, I have to say, I don't know how to use composer whatsoever. I tried following a tutorial and I think I got it installed, who knows, lol. But when I tried to do 2 things: run php composer.phar update I get [ComposerDownloaderTransportException] The "https://repo.magento.com/packages.json" file could not be downloaded: Failed to enable crypto failed to open stream: operation failed And then when I try to run php bin/magento setup:upgrade I get this: Magento supports PHP 5.6, 7.0.2, and 7.0.6 or later. Please read http://devdocs.magento.com/guides/v1.0/install-gde/system-requirements.html Can you help me? I'm not sure what I need to do.

Leave Comment

Newsletter

Latest Tweets