I have created a menu name My Menu (machine name: my_menu ) with menu item My Nodes and My messages. Now I want alter My nodes and My messages link title. So the menu items should look like Nodes and Messages instead of My nodes and My Messages.

So I don't understand and also didn't find how can I alter the menu link title programmatically. i am trying to use hook_menu_alter(&$items) and hook_menu_link_alter(&$item), but it doesn't give any result.

So can anyone please tell me how can I alter the menu link items title?

Thanks in advance

  • Are you using D7 or D8?
    – CodeNext
    Sep 5, 2016 at 8:41

1 Answer 1


Use theme_link function for altering your link markup. I have recently come across a scenario where I needed to change my account name to user name I did with the following code.

function THEMENAME_link($variables) {
  if ($variables['text'] == "My account") {
    $variables['text'] = $GLOBALS['user']->name;

return '<a href="' . check_plain(url($variables['path'], $variables['options'])) . '"' . drupal_attributes($variables['options']['attributes']) . '>' . ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) . '</a>';

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.