Skip to main content

theme_menu_links

Forcing all menu links to use absolute links in Drupal 8

In a recent project, we were using an external service that pulls our site into their system and injects their content into our project. The issue we ran into was that the third party was overwriting all links in the template we provided with their HTTP host, causing the menu system from our Drupal site to break. To get around this we needed to generate absolute links for all of our menus.

In order to accomplish this we used template_preprocess() to dynamically provide our site's hostname as a variable:


Theme_menu_links: How to target a specific menu in Drupal

Today we needed to override the menu links of one menu on our Drupal 7 site. We started with theme_menu_links(), but quickly decided that we didn't want to figure out what menu every menu link belonged to. After some searching we discovered this comment (https://api.drupal.org/comment/26939#comment-26939) which suggested using this naming structure:

THEMENAME_menu_link__MENU_NAME()