1

I defined a menu through hook_menu, and set a title callback on a menu item, like so:

function mymodule_foobar_menu() {
     $items[SOMEPATH] = array(
    'title'         => t('Drink'),
    'title callback' => 'mymodule_foobar_menu_title',
    'access callback' => (blah),
        'page callback' => 'blah',
        'type' => MENU_NORMAL_ITEM,
        'menu_name' => 'main-menu',
        '#description' => '',
        'weight'=>10
    );

and created

function mymodule_foobar_menu_title() 
{
    return ($whatever)?t('Beer'):t('Wine');
}

mymodule_foobar_menu_title seems to be called for almost everywhere where 'Drink' would appear, showing 'Beer' or 'Wine' instead. Except, in the main menu itself.

I can edit the main menu (at admin/structure/menu/manage/main-menu) and I see the link mentioned as Wine (or Beer). If I edit the link, there is a textbox 'Menu link title *' that says 'Drink'.

Can someone explain how to change the text of the link, instead of all the other appearances of the title, preferably without using an extra module ?

2
  • I think the title callback is for the page, not the menu link (routes and links are two separate things even though hook_menu() convolutes them a bit). The simplest solution I can think of would be to install Menu Token and define a custom token in your module
    – Clive
    Dec 28, 2013 at 18:53
  • Aw, that makes sense. I would like a solution without Yet Another Module, though. Updating the question.
    – commonpike
    Dec 28, 2013 at 20:04

0

Your Answer

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

Browse other questions tagged or ask your own question.