Drupal Alters and Overrides: hook_menu_alter
Submitted by Brenda Boggs on
This brief tutorial will cover altering and removing items in Drupal's menu system. See my previous blog post on hook_form_alter.
hook_menu_alter
Introduced in Drupal 6, hook_menu_alter allows you to actually alter elements in Drupal's menu system. The primary links, secondary links, tabs and page callbacks are alterable in this way. For example-- using the Content Profile module, it adds an extra tab to each user's page. If I choose the option to "Show a tab at the user's page", it will then display an extra tab when visiting that profile.


The problem with this is I find the tabs a bit unclear and want to rename them; instead of "View", "Edit" and "Profile", I want them to say "View", "Edit Account Settings", and "Edit Personal Information".
In my demo module, I'll add the following:
/**
* Implementation of hook_menu_alter().
*/
function demo_menu_alter(&$items) {
// Change the name of user profile tabs.
$items['user/%user_category/edit']['title'] = 'Edit Account Settings';
$items['user/%user/profile/profile']['title'] = 'Edit Personal Information';
}
You can, of course, also remove menu items or tabs this way. You can find and target your specific menu item with a print_r($items) or dpm($items).
/**
* Implementation of hook_menu_alter().
*/
function demo_menu_alter(&$items) {
// Change the name of user profile tabs.
$items['user/%user/profile/profile']['title'] = 'Edit Personal Information';
unset($items['user/%user_category/edit']['title']);
}
In Drupal 6, you can also use the Tab Tamer module.

2 Comments
what a great post, just
Submitted by HardyLatte (not verified) on
what a great post, just signed up to your RSS feed and hope to read more of your posts in the future. keep it up!
Thanks! Wish I had more time
Submitted by Brenda Boggs on
Thanks! Wish I had more time to post but hopefully you found it helpful.
Add new comment