PHP code in menu links One of many things I want to do in Drupal is to have 

Hi: "User name" 


link for /users page. (In the future I also want to have a control over visibility of menu tabs and their links depending on the logged user.)

Currently I have a quick, easy and relaxing solution - hacked page.tpl.php which works perfectly. Unfortunately I it is not a perfect (nor profesional) solution because the website will brake down as soon as I update the drupal core.

Is there any way of injecting php code into menu link/title without messing up the core?

I've been thinking about using translation module, menu module, and others but so far I have not been successful. I know that menus in drupal are designed to be static, but there must be a walk-around.

I know that menu_token can solve some of my problems but it does not work for me (when installed I have memory allocation issues in php server or crashing MYSQL).
I finally figured this out.
YES it is possible to have dynamic menus in Drupal.

You start by enabling dynamic access to menu item with the ['alter'] flag and hook_menu_link_alter(&amp;$item).

function mycode_menu_link_alter(&amp;$item) {
    if($item['menu_name'] == 'user-menu'){
        $item['options']['alter'] = TRUE;
    }
}


Note that menu_link_alter works on a menu item (not the whole menu) and needs to be trigered by editing and saving that item (for example disable->save->enable->save->).

Once the menu item is activated, I can use
hook_translated_menu_link_alter(&amp;$item, $map)

function mycode_translated_menu_link_alter(&amp;$item, $map){
    //drupal_set_message("Menu: ".$item['menu_name']." Item: ".$item['title']
    if($item['menu_name'] == 'user-menu'){
        global $user;
        $item['title'] = "Hi: $user-&gt;name";
    }
}


Other very useful thing you can do is to disable the menu link

$item['hidden'] = TRUE;


or (my favorite) change the links

[...];    
if($item['menu_name'] == 'main-menu'){
   switch ($item['title']){
       case "Home":
            $item['href'] = 'not/home/page';
[...]