How to Add Custom Admin Menu In Magento 2

by Fayyaz Khattak  March 6, 2017

Magento developers look forward to new and modern features in Magento 2 to get the most out of the popular CMS right out-of-the-box. When we talk about Magento 2 development, there is always a need for custom options that are required to be placed somewhere in the platform. While creating a Magento 2 module, I needed to add a custom admin menu in the Magento 2 Admin Panel.

Add Custom Admin Menu In Magento 2

To solve this issue, I spent some time on it and found a solution. In this blog post, I will try to describe how to add a custom admin menu in Magento 2 briefly. Just to accomplish this job, I will be creating a custom module. It will be like a dummy admin menu. When you click on it, nothing will happen.

Let’s start with creating a Magento 2 module. Here is an excellent article was written on how to create a simple module in Magento 2. I will be using Cloudways as a Module’s Namespace and Adminmenu as Module’s Name.

Create a new registration.php file in Magento2Root/app/code/Cloudways/Adminmenu/ and add the code below to it:

Now to declare the module, create a module.xml file in Cloudways/Adminmenu/etc/ with the following code:

Admin menu is handled by the file menu.xml. This file consists of <config>, <menu> and <add> elements. <menu> element may consist of multiple <add> elements as well.

Create a new file menu.xml in Cloudways/Adminmenu/etc/adminhtml/ and add the following content to it:

As you can see the menu.xml file, we have defined two <add> element with attributes. First one is used for first level menu and the second one is for the second level menu with additional actions and parent attributes.

Here is an explanation of each attribute:

id – unique identifier

title – title of the menu that will be showing in the admin

module – indicates the module

sortOrder – prioritize the place of menu

resource – the rule to identify which admin user see and access this menu

action – link to the specified admin controller

parent – defines on which first level menu it depends

Finally, everything is ready that will add custom admin menu in Magento 2 Admin Panel. To enable and activate the custom module, run the following CLI commands:

In the end, it will look something like this:

Custom Admin Menu Magento 2

That’s all. The custom admin menu in Magento 2 should now be visible. I hope now you have a fair idea about the concept of using menu.xml in Magento 2. If you have any questions, please leave a comment below. If you like this blog post, thank me by sharing it with your Magento fellows using Facebook, Google+, or Twitter. Happy learning! 🙂

Start Creating Web Apps on Managed Cloud Servers Now!

Easy Web App Deployment for Agencies, Developers and E-Commerce Industry

About Fayyaz Khattak

Fayyaz is a Magento Community Manager at Cloudways - A Managed Magento Hosting Platform. His objective is to learn & share about PHP & Magento Development in Community. Fayyaz is a food lover and enjoys driving. You can email him at m.fayyaz@cloudways.com

Stay Connected:

You Might Also Like...