Text or Call 303.473.4400
Select Page

So, in this article I’ll give you a handy script to add a home link to the top menu.

In magento 1.7, the menu is now created via an *event* (page_block_html_topmenu_gethtml_before)

The catalog observer hooks into this and adds menu items as Varien_Data_Tree_Node objects.

I have some samples here to show you how to add a link at the beginning of this menu.

config.xml portion:

Copy The Code:



observer portion:
Class Cp_Layout_Model_Observer
* Adds additional links to the top menu
* @param Varien_Event_Observer $observer
public function addTopMenuItems(Varien_Event_Observer $observer)
$nodeId = “home”;
$menu = $observer->getMenu();
$tree = $observer->getMenu()->getTree();

$data = array(
“name” => “Home”,
“id” => $nodeId,
“url” => Mage::getBaseUrl(),
“is_active” => Mage::getSingleton(‘cms/page’)->getIdentifier() == ‘home’ && Mage::app()->getFrontController()->getRequest()->getRouteName() == ‘cms’
$homeNode = new Varien_Data_Tree_Node($data, ‘id’, $tree, $menu);
$this->_prependNode($homeNode, $menu);


protected function _prependNode($node, $menu)
$nodeId = $node->getId();
$readded = array();
foreach($menu->getChildren()->getNodes() as $n)
if ($n->getId() != $nodeId)
$readded[] = $n;
foreach($readded as $r)

Pin It on Pinterest

Share This