6.x core.php hook_menu_link_alter(&$item, $menu)
7.x system.api.php hook_menu_link_alter(&$item)

Alter the data being saved to the {menu_links} table by menu_link_save().


$item: Associative array defining a menu link as passed into menu_link_save().

See also


Related topics

2 functions implement hook_menu_link_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

user_menu_link_alter in modules/user/user.module
Implements hook_menu_link_alter().
user_translated_menu_link_alter in modules/user/user.module
Implements hook_translated_menu_link_alter().
1 invocation of hook_menu_link_alter()
menu_link_save in includes/menu.inc
Saves a menu link.


modules/system/system.api.php, line 1305
Hooks provided by Drupal core and the System module.


function hook_menu_link_alter(&$item) {

  // Make all new admin links hidden (a.k.a disabled).
  if (strpos($item['link_path'], 'admin') === 0 && empty($item['mlid'])) {
    $item['hidden'] = 1;

  // Flag a link to be altered by hook_translated_menu_link_alter().
  if ($item['link_path'] == 'devel/cache/clear') {
    $item['options']['alter'] = TRUE;

  // Flag a link to be altered by hook_translated_menu_link_alter(), but only
  // if it is derived from a menu router item; i.e., do not alter a custom
  // menu link pointing to the same path that has been created by a user.
  if ($item['link_path'] == 'user' && $item['module'] == 'system') {
    $item['options']['alter'] = TRUE;


jackocnr’s picture

Note that if you want to set a link path to a URL containing arguments, you cannot do it in $item['link_path']. Instead you have to do it like this:

$item['options']['query']['ARGUMENT_NAME'] = 'ARGUMENT_VALUE';

That is unless anyone else has a better way??

mathieso’s picture

... but this did:

$item['localized_options']['query']['og_group_ref'] = $nid;
hwi2’s picture

You can add this option to the hook_menu_link_alter:

function MODULENAME_menu_link_alter(&$item)
		$item['options']['attributes']['target'] = '_blank';
Drupa1ish’s picture

https://drupal.org/comment/8134093#comment-8134093 confirms also that the above is not working
Try this in template.php, for D7

function YOURTHEME_link($variables) {
  $variables['options']['attributes']['target'] = '_blank';
  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>';
JeffC518’s picture

I can also confirm that the solution proposed on https://api.drupal.org/comment/45108#comment-45108 does not work in D7. This one does: https://api.drupal.org/comment/54068#comment-54068

arnoldbird’s picture

This hook does not fire in my module or in my theme, even after clearing the cache.

kevla’s picture

This hook only fires when a menu link is saved.

BartK’s picture

I found this thread looking for how to alter a menu item when it's loaded.

The function you need is hook_menu_get_item_alter()