1 menu_example.module menu_example_menu_alter(&$items)

Implements hook_menu_alter().

Changes the path 'examples/menu_example/menu_original_path' to 'examples/menu_example/menu_altered_path'. Changes the title callback of the 'user/UID' menu item.

Change the path 'examples/menu_example/menu_original_path' to 'examples/menu_example/menu_altered_path'. This change will prevent the page from appearing at the original path (since the item is being unset). You will need to go to examples/menu_example/menu_altered_path manually to see the page.

Remember that hook_menu_alter() only runs at menu_rebuild() time, not every time the page is built, so this typically happens only at cache clear time.

The $items argument is the complete list of menu router items ready to be written to the menu_router table.

Related topics

File

modules/examples/menu_example/menu_example.module, line 457
Hook implementations for the Menu Example module.

Code

function menu_example_menu_alter(&$items) {
  if (!empty($items['examples/menu_example/menu_original_path'])) {
    $items['examples/menu_example/menu_altered_path'] = $items['examples/menu_example/menu_original_path'];
    $items['examples/menu_example/menu_altered_path']['title'] = 'Menu item altered by hook_menu_alter()';
    unset($items['examples/menu_example/menu_original_path']);
  }

  // Here we will change the title callback to our own function, changing the
  // 'user' link from the traditional to always being "username's account".
  if (!empty($items['user/%user'])) {
    $items['user/%user']['title callback'] = 'menu_example_user_page_title';
  }
}