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! So how to create custom menu in Magento?
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 in Magento 2
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:
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!