cancel
Showing results for 
Search instead for 
Did you mean: 

Disable Parent Link

Disable Parent Link

How do I disable the link on a parent category? I only want the sub categories to be clickable.

4 REPLIES 4

Re: Disable Parent Link

hi @b7itzz


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 add to app/code/local/Mage/Catalog/Block
3. Go to function _renderCategoryMenuItemHtml(), line 285 and put the above code:

Remove the <a></a>  or simply add onclick="return false;"

 

  if($category->getLevel()== 2 && $hasActiveChildren) {
                $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.' onclick="return false;">';
                $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>';
    } 

Source

Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

Re: Disable Parent Link

Unfortunately, this workaround doesn't work.

Re: Disable Parent Link

hi @b7itzz

 

try this solution

copy to local Mage/Page/Block/Html/Topmenu.php

 

and replace

$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
                . $this->escapeHtml($child->getName()). '</span></a>';

with

if($child->getLevel()==0):

            $html .= '<span>'
                . $this->escapeHtml($child->getName()) . '</span>';    
                else:
            $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
                . $this->escapeHtml($child->getName()). '</span></a>';
             endif;
Find helpful ? Consider Giving Kudos to this post.
Problem solved? Click Accept as Solution!"
Qaisar Satti

Disable Parent Link with jQuery

If you would like a jQuery solution, this does the trick.  Granted, it's possible if JS doesn't load or is broken then the parent links will come back.  so if it's a deal killer if they are accidentally shown in circumstances like this then it's not the ideal option, but it's good for a quick solution assuming you already have jQuery loaded up.

 

Add this inside your jQuery .ready and tweak the CSS selectors if needed.

 

$('#header-nav .level0.parent > a').contents().unwrap();