Remove Specific Href from Top-Menu Link in Magento – How to

category-treemenutheme

I have an specific cateogry (top-level / main category) witch shows a menu on hover at menu.
I need to remove the href from that < li> item, or replace href value for "javascript:void(0);".

I'm trying to do this with page_block_html_topmenu_gethtml_before and page_block_html_topmenu_gethtml_after observers, but didn't get it yet.

I wouln't like to make a replace in block's html output. I don't think it's a good idea. =O

Does anyone have any idea?

Best Answer

To remove url, href functionality of the top menu categories, you can take the following steps:

  1. Create some folder as this path: app/code/local/Mage/Catalog/Block
  2. Copy file Navigation.php from app/code/core/Mage/Catalog/Block to app/code/local/Mage/Catalog/Block
  3. Go to function _renderCategoryMenuItemHtml()

Replace this code

$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';

with this code

if($category->getLevel()== 2 && $hasActiveChildren) {
            $html[] = '<a href="[removed]void(0);"'.$linkClass.'>';
            $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
            $html[] = '</a>';
} else {
            $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
            $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
            $html[] = '</a>';
}