By davedelong on
Hey everyone,
I'm looking to add other attributes to menu links before they're rendered. I know that _menu_link_build is where basic menu item construction is done prior to rendering, but is there some hook that I can implement in order to add something else to the attributes array?
Thanks,
Dave
Comments
*bump*
*bump* (again)
and another bump.... I could
and another bump....
I could really use an answer to this...
hook_menu_link_alter() or theme_menu_item_link()
You can override the theme_menu_item_link() function in your theme's template.php
http://api.drupal.org/api/function/theme_menu_item_link/6
-OR-
Use the hook_menu_link_alter() function to modify any menu item before it is inserted or updated into the menu links table.
http://api.drupal.org/api/function/hook_menu_link_alter
Here is a snippet that I use to add a link's title to the link's class attribute.
The benefit of the using hook_menu_link_alter() is it will only execute once when a menu link is created or updated. The con is you have to rebuild your menus (using the Devel module) to initialize any changes and custom menu items, including nodes, need to be resubmitted for the link attributes to be altered.
You could also try one of the modules.
- Menu attributes - http://drupal.org/project/menu_attributes
- Menu class - http://drupal.org/project/menuclass
Thanks for the code and
Thanks for the code and links! I was looking for functionality like menu_attributes offers, and decided to use that instead. Beats having to write my own module. =)
Thanks again,
Dave
Get great Drupal hosting at MM Hosting. (I don't work for them; I'm just a very satisfied customer)