Magewallet

Magento 2 Extensions, Themes & Services

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.

1)registration.php
2)composer.json
3)etc/module.xml
4)etc/frontend/events.xml
5)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!!

Mahendra Paladiya
Mahendra is a Web Developer whose passions includes web development, technical blog writing, and database management. His passion for web development pushed him into learning how to handle different platforms like Core PHP, Magento, Prestashop, WordPress, CodeIgniter, CakePHP and Oracle.

2 Comments

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

  2. 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

    [Composer\Downloader\TransportException]
    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 a Reply

Your email address will not be published.

*

 

© 2017 Magewallet

Theme by Anders NorenUp ↑