How to Add Custom Menu Item in Magento 2 Frontend

How to Add Custom Menu Item in Magento 2 Frontend

Navigation menu in a store eases the navigation of the store from one location to another. It directs website visitors to find products and services easily without wasting time.

By default, Magento 2 generates the menu link while adding the category and enabling “Include in Menu” option of the category. But what if you require to add custom menu item in Magento 2 frontend rather than category links for website users to easily locate the link of an important page or form?

For example, you require to show user information of the logged in customers under the page named “My Profile”. To easily highlight and find the link, you require to add custom menu item in Magento 2 frontend for customers to click and open the profile information.  

There are two separate methods to add custom menu item in Magento 2 frontend:

  1. Using Plugin
  2. Using Event and Observer

Programmatic Solution to Add Custom Menu in Magento 2 Frontend

Method 1:

  1. You have to create a plugin. Create di.xml at [vendor]/[extension]/etc/frontend/
  2. Create Topmenu.php at [vendor]/[extension]/Plugin/

Method 2:

  1. Create events.xml file at [vendor]/[extension]/etc/frontend
  2. Now create Topmenu.php  file at [vendor]/[extension]/Observer

That’s it. Once you implement one of the above methods to add custom menu item, you can see the menu item added in the Magento 2 frontend.

add custom menu item in magento 2 frontend

If you have queries, feel free to ask in the Comment section below.

I would be happy to answer.

Please do consider sharing this post with Magento Community via social media.

Thank you.

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

5
(based on 11 Reviews)

Amit was a Magento developer at Meetanshi. He has good experience in Information Technology and education field over more than 8 years.

Leave a reply:

Your email address will not be published.