Skip to content

How to add an id for each menu item in Joomla default menu?

Because Joomla menu adds an id only for the current menu item, this is the hack to add an id for all menu items:


For legacy vertical type of menu go to www.yoursite.com/modules/mod_mainmenu/legacy.php

On line 75 there is:

} else {
$id = '' ;
}

Just add this insted:

} else {
$id = 'id="menu_item' . $mitem->id . '"' ;
}

This will add an unique id to the li tag.

For the default list menu go to www.youriste.com/modules/mod_mainmenu/tmpl/default.php

On line 72 there is this code:

} else {
$node->removeAttribute('id');
}

Change it to this:

} else {

}

This will add an unique id to the li tag.

Also go to www.yoursite.com/modules/mod_mainmenu/helper.php and find the following code on line 358:

switch ($tmp->browserNav)
{
default:
case 0:
// _top
$data = ‘<a href=”‘.$tmp->url.'”>’.$image.$tmp->name.'</a>’;
break;

And Change it to:

switch ($tmp->browserNav)
{
default:
case 0:
// _top
$data = ‘<a href=”‘.$tmp->url.'” id=”menu_item’.$tmp->id.'”>’.$image.$tmp->name.'</a>’;
break;

This will add an unique id to the a tag.

Published inCodingJoomla

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*