Adding custom Magento menu

Adding custom Magento menu

September 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Adding custom Magento menu

Creating Custom Menus in Magento: Step-by-Step Guide

Adding custom menus to your Magento store can significantly enhance user navigation and improve e-commerce experience. In this guide, we’ll walk through the process of creating a custom menu that links to internal pages within your Magento site.

Understanding Magento Menu Structure

Magento’s menu structure is built using XML files located in app/design/frontend/[your_package]/[your_theme]/layout. The main menu is defined by the catalog.xml file, which specifies the menu items and their URLs. To add custom links, you’ll need to modify this file or create a new one.

Creating a Custom Menu

To begin, open your terminal and navigate to your Magento root directory:

cd /path/to/your/magento/installation

Next, we’ll create a new layout XML file for our custom menu. Open your preferred text editor and create a new file named custom_menu.xml in the following location:

/app/design/frontend/[your_package]/[your_theme]/layout

In this file, define your custom menu structure as follows:

<?xml version="1.0" encoding="UTF-8"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="catalog.topnav">
            <block class="Magento\Theme\Block\Html\Topmenu" template="html/topmenu.phtml" after="-">
                <arguments>
                    <argument name="configure" xsi:type="array">
                        <item name="topMenuItemClass" xsi:type="string">custom-menu-item</item>
                        <item name="template" xsi:type="string">Magento_Theme::html/topmenu_custom_item.phtml</item>
                    </argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

In this example, we’re extending the existing catalog.topnav reference block to include our custom menu. We specify a new template file (topmenu_custom_item.phtml) that will be used for formatting our custom links.

Now let’s add the actual links to your custom menu. Open or create the following XML file:

/app/design/frontend/[your_package]/[your_theme]/etc/cms.xml

Within this file, define your custom menu items within the <menu> tag:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/config.xsd">
    <menu>
        <add id="Magento_Backend::custom_menu_item">
            <title>Custom Menu Item</title>
            <sort_title>50</sort_title>
            <parent_id>Magento_Cms::cms_page_manager</parent_id>  <!-- Change this to your desired parent ID -->
            <url path="" target="_self" />
        </add>
    </menu>
</config>

Replace Custom Menu Item with the name of your link. Set the sort_title to determine the position of your menu item. The parent_id should correspond to a valid Magento menu item ID (e.g., Magento_Cms::cms_page_manager).

Creating the Custom Menu Template

Finally, we need to create the visual template for our custom links. In your front-end theme directory:

/app/design/frontend/[your_package]/[your_theme]/template/Magento_Theme/html

Create a new file named topmenu_custom_item.phtml and add the following code:

<li class="level0 nav-5 level1 item">
    <a href="{$block.getUrl()}" title="{$block.title}" class="level0">
        <span>{$block.label}</span>
    </a>
</li>

This template will display a simple link with the label and URL defined in your cms.xml file.

Conclusion

Creating custom menus in Magento requires understanding the layout structure, XML configuration files, and theme templates. By following this guide, you can easily add internal links to your navigation menu, enhancing the user experience of your e-commerce store.

Remember to clear your cache after making changes for them to take effect. You can do so using the command:

bin/magento cache:clean

For more advanced customizations and a deeper understanding of Magento’s layout system, consider exploring our comprehensive Magento development guides at Laravel Company.

Happy coding!

Catalog Themes Configuration

Our network