How To Add a Custom Admin Menu in Magento 2

How to add a custom admin menu in Magento 2
Posted in: Magento 2 Guides

Magento 2 is a robust platform with loads of useful options and features. But from a development point of view, sometimes the provided options don’t fulfill all the requirements of a project, hence, custom options are required to complete some tasks. And a custom admin menu is among those you can implement yourself to improve your Magento admin workflow.

Today, in this guide, you are going to learn how to add a custom admin menu in Magento 2.

First, I will create a custom module and then a custom admin menu!

Configure and register a custom module in the Magento 2 menu xml

Create registration.php in app/code/Demo/Mymenu/ to register the module. Paste this code to it:

Now create module.xml in app/code/Demo/Mymenu/etc to configure the module and paste the following code into the newly created file:

Create a custom admin menu

Create menu.xml in app/code/Demo/Mymenu/etc/adminhtml to create a custom admin menu and paste the following code into the newly created file:

In the code above, there are two <add> attributes. The first one is for first level menu, and the other one is for second level attribute.

Here's the explanation of the entities used in the code:

id: is used as the unique identifier of a menu.

title: the menu title that will be displayed in the admin menu.

module: the module that I have created (Demo_Mymenu).

sortOrder: is used to set the placement of menu.

resource: a rule to identify which admin user can see this menu.

action: is used to link an admin controller

parent: is used to define which menu level it depends on.

Launch the SSH terminal

All done! Now just connect your store using SSH and run these commands in the root directory of the store:

Log in to the admin panel of your Magento 2 and you will see the new menu if everything was done correctly:

a custom admin menu added

I hope after following this tutorial you can now successfully add a custom admin menu in Magento 2. If you still have any confusions, just leave a comment below and I will get back to you!

July 27, 2017
August 18, 2017
July 19, 2017
Comments
Rav
November 24, 2018
Hey Syed, This looks great. Sorry I'm learning, so if my question does not illustrate properly please bear with me. What I'm trying to do is create a register/ login screen from my main (default) page, but i wanted it to have 2 different kinds of login/register. 1)personal, 2) Business... I have already created a personal store, and a business store and they would both have different information on each (B2C, AND B2B). What my goal is to get rid of the login, register from all 3 stores (main (default), personal, and Business) and just put it on the middle of the screen of main instead of it being on the top right hand corner (that's all i want on the main screen), but once logged in it would take you to the appropriate store. would it be possible for you to advise me on how to do this? Thank you Syed,
Reply
Leave your comment

Your email address will not be published

This blog was created with Amasty Blog Pro

This blog was created with Amasty Blog Pro

© 2009-2022 Amasty. All Rights Reserved.