Search code examples
drupaldrupal-7drupal-theming

Can I modify theme_menu_link for a specific menu?


I would like to add pipes ("|") between menu items for one of the menus on my Drupal 7 site (theme name is "thompson"). I figured the best way to do this is to create a function in my template.php file called thompson_menu_link. I did that and it is successfully modifying the menus, but it's changing all the menus. Is there a way I can do this for just one menu on my site?

Currently, I used the admin pages to add my footer menu (url path: menu-footer-menu) to the Footer block. Should I call it a different way?


Solution

  • Apparently Drupal core provides the ability to theme menu links by menu name. For the Main menu the following theme function should work

    THEMENAME_menu_link__main_menu()
    

    Alternatively you could use the Menu Block module to create menu blocks. Among other things the module creates additional theme suggestions. From the module's README:

    Menu block uses Drupal core's menu theme functions. However, it also provides theme hook suggestions that can be used to override any of the theme functions called by it. ...

    • theme_menu_link() can be overridden by creating one of:
      • [theme]_menu_link__[menu name]()
      • [theme]_menu_link__menu_block()
      • [theme]_menu_link__menu_block__[menu name]()
      • [theme]_menu_link__menu_block__[block id number]()