0

theme_menu_link allegedly "Returns HTML for a menu link and submenu."

In attempting to use this 'hook' I added code to my template.php as such:

function themename_menu_link(array $vars) {
  dpm($vars);
}

It didn't work. Nothing appears.

I confirmed that the template.php code is executing and cleared caches several times.

Every other hook_ or theme_ function I've tested runs without issue, however this one does not.

I've also tested the alternative method, themename_menu_link__your_menu_name with no success. The code seems to be ignored.

5
  • Can you confirm it is being hit with either an exit or xdebug breakpoint? Just to clarify, you aren't literally calling it themename_menu_link are you?
    – Kevin
    Commented Jun 29, 2017 at 15:40
  • 1
    What (base) theme are you using? Some don't use menu_tree_output, and as such don't invoke that theme function
    – Clive
    Commented Jun 29, 2017 at 16:23
  • @Kevin no, the theme is foo, and the function is foo_menu_link :) I think Clive might have hit the nail though. I'll check back in a few.
    – Dooley
    Commented Jun 29, 2017 at 18:31
  • I think you're right, @Clive. I'll post back in a few.
    – Dooley
    Commented Jun 29, 2017 at 18:32
  • @Clive you are correct, the theme_menu_link does not fire on all default menus implemented in a theme. Changing over to block menus fixed the issue.
    – Dooley
    Commented Jun 29, 2017 at 22:53

1 Answer 1

-1

Try print_r instead of dpm --

function theme_menu_link(array $variables) {
  return print_r($variables['element']);
}

or use hook_menu_link_alter --

hook_menu_link_alter($variables){
  var_dump($variables);
}
1
  • The print_r you suggest would require the boolean set to true to actually work; but thank you all the same.
    – Dooley
    Commented Jun 29, 2017 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.