0

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?

1

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>';
}
  • I found this post because i needed this solution too... and it works great... however... it creates an issue in mobile menu... how to solve that? In the mobile menu the Menu Item that has it's linked removed in normal view is a link again, leading to a 404 page now. – carlo Apr 22 '15 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.