How To Create Admin Menu In Magento 2

Steps to create Admin Menu

Create menu.xml

Directory

app/code/VendorName/ModuleName/etc/adminhtml/menu.xml

Content for menu.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
    <menu>
        <add id="VendorName_ModuleName::newmenu" title="New Menu" module="VendorName_ModuleName" sortOrder="51" resource="VendorName_ModuleName::newmenu"/>
        <add id="VendorName_ModuleName::configuration" title="Configuration" module="VendorName_ModuleName" sortOrder="10" action="vendorname_modulename/configuration" resource="VendorName_ModuleName::configuration" parent="VendorName_ModuleName::newmenu"/>
        <add id="VendorName_ModuleName::management" title="Management" module="VendorName_ModuleName" sortOrder="99" parent="VendorName_ModuleName::newmenu" action="vendorname_modulename/management" resource="VendorName_ModuleName::management"/>
    </menu>
</config>

Let's explain the attributes:

  • The id the attribute is the identifier for this note. It’s a unique string and should match the format: {Vendor_ModuleName}::{menu_description}.
  • The title the attribute is the text which will be displayed on the menu bar.
  • The module the attribute has defined the module to which this menu belongs.
  • The sortOrder the attribute has defined the position of the menu. A lower value will display on top of the menu.
  • The parent the attribute is an Id of another menu node. It will tell Magento that this menu is a child of another menu. 
  • The action an attribute will define the URL of the page to which this menu links.
  • The resource the attribute is used to define the ACL rule which the admin user must have in order to see and access this menu.

Flush Magento Cache

To clear cache, run the following command

php bin/magento cache:clean

If you are looking for a Magento developer, visit Magento Developer Agency.