1

I want a menu item in main menu which the hyperlink is # or javascript:void(0), instead of by default it will show the category products, any method i can do that?

asked Dec 28, 2015 at 3:57
1
  • can you share your magento version or add tag in magento ver? Commented Dec 28, 2015 at 6:14

1 Answer 1

2

You need to do some customization using magento event/observer.

The page_block_html_topmenu_gethtml_before event lets us add new links in the menu, to # or javascript:void(0) or anything else.

Observer code

<?php 
class [Namespace]_[Module]_Model_Observer {
 public function addItemsToTopmenuItems($observer) {
 $menu = $observer->getMenu();
 $tree = $menu->getTree();
 $action = Mage::app()->getFrontController()->getAction()->getFullActionName();
 $nodeId = 'some-node-id';
 $data = array(
 'name' => Mage::helper('catalog')->__('Title goes here'),
 'id' => $nodeId,
 'url' => '#', // any URL for the href attribute
 );
 $node = new Varien_Data_Tree_Node($data, 'id', $tree, $menu);
 $menu->addChild($node);
 return $this;
 }
}

config.xml code

<frontend>
 <events>
 <page_block_html_topmenu_gethtml_before>
 <observers>
 <[module]>
 <class>[module]/observer</class>
 <method>addItemsToTopmenuItems</method>
 </[module]>
 </observers>
 </page_block_html_topmenu_gethtml_before>
 </events>
</frontend>

See more details at Adding links to category menu

answered Jan 15, 2016 at 23:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.