Magento Basic Setting - How to add a “Home” link to the top menu?

How to add a “Home” link to the top menu?

Magento 2 is awesome, now you can learn and practice every thing about Magento 2 with

Magestore Ultimate Magento 2 Tutorial

More than 150 tips, guides and tutorial. Everything is Free forever.

50 000 Magento developers have joined, explore Magento 2 in the easiest way today!

This is 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.

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

config.xml portion.

Copy the code below:

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)


Other Answers in the Category "Magento Basic Setting"