How to add a new item to the navigation menu in Magento

Adding a new item to the navigation menu is fairly simple.

We will add this ability to a custom module. There is no need to modify core Magento files or templates and layouts.

First, we need to rewrite the block that is responsible for menu drawing; however, we will not be using a <rewrite> tag. The reason for this is, if the module is disabled, Magento will break. Instead, will will use an observer for it.

At global scope, in your config.xml file, add the following code:


You can also use other events instead of controller_action_layout_generate_blocks_after. Next, you must create Observer.php in the Model folder using method regenerateMenu

class Company_ModuleName_Model_Observer

public function regenerateMenu($observer)
  // if module is active
  if (!Mage::getStoreConfig('advanced/modules_disable_output/Company_ModuleName'))
    $layout = Mage::getSingleton('core/layout');

    // remove all the blocks you don't want
    $layout->getUpdate()->addUpdate('<remove name="catalog.topnav"/>');

    // load layout updates by specified handles

    // generate xml from collected text updates

    // generate blocks from xml layout


Next step: you should create the block file Navigation.php with the following code:

class Company_ModuleName_Block_Navigation extends Mage_Catalog_Block_Navigation

public function renderCategoriesMenuHtml($level = 0, $outermostItemClass = '', $childrenWrapClass = '') 

  // if route is active
  $active = ($this->getRequest()->getRouteName()=='yourroute' ? 'active' : '');

  // Get navigation menu html
  $html = parent::renderCategoriesMenuHtml($level, $outermostItemClass, $childrenWrapClass);

  // if module is active
  if (Mage::helper('core/data')->isModuleEnabled('Company_ModuleName')) {
    // Adding new menu item. You can also add few items or child elements there
    $html .=  "<li class='$outermostItemClass $active'><a class='$outermostItemClass' href='" . Mage::getUrl('yourroute') . "'><span>" . Mage::helper('yourroute')->__('New Menu Item') . "</span></a></li>";
  return $html;

Note: Don’t forget to declare the block in your config.xml file.
After, you need to declare the path for your layout XML in config:


Lastly, here is content for newmenuitem.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <reference name="">
     <!--Note: use custom block file for menu drawing and default template file-->
      <block type="yourroute/navigation" name="newmenu.topnav" template="catalog/navigation/top.phtml">

Now you will have successfully added a menu item without modifying core files.
Happy coding!

Read more: