hook_menu_alter() is not working I have implemented hook_menu_alter() in a module I have created. I have printed something inside that function call but nothing shows up, though the function hook_init() is executed from the same module. The output of hook_init() shows up in the page, but not from the hook_menu_alter() even after clearing the cache.

Does anybody have any idea regarding this issue?

function mymodule_init(){
print "here";
}

function mymodule_menu_alter(&amp;$items) {
print "I am here";
return $items;
}
hook_menu() and hook_menu_alter() are not always invoked; they are invoked only when Drupal rebuilds the menus, such as when a module is enabled, disabled, and updated, or when the Drupal cache is cleared.

Anatomy of hook_menu reports the following sentence:


  hook_menu() is called rarely, such as when modules are enabled. If you edit a module’s hook_menu(), you must visit admin/build/modules for the changes to take effect.


The function that invokes the implementations of hook_menu() and hook_menu_alter() is menu_router_build(), which contains this code (the code is for Drupal 7):

function menu_router_build() {
  // We need to manually call each module so that we can know which module
  // a given item came from.
  $callbacks = array();
  foreach (module_implements('menu') as $module) {
    $router_items = call_user_func($module . '_menu');
    if (isset($router_items) &amp;&amp; is_array($router_items)) {
      foreach (array_keys($router_items) as $path) {
        $router_items[$path]['module'] = $module;
      }
      $callbacks = array_merge($callbacks, $router_items);
    }
  }
  // Alter the menu as defined in modules, keys are like user/%user.
  drupal_alter('menu', $callbacks);
  list($menu, $masks) = _menu_router_build($callbacks);
  _menu_router_cache($menu);

  return array($menu, $masks);
}


The function is called by menu_rebuild(), which is then called by:


drupal_flush_all_caches()
menu_enable(), the implementation of hook_enable()
menu_uninstall(), the implementation of hook_uninstall()
12 other functions, and 1 method


drupal_flush_all_caches() is invoked by system_modules_submit(), which is the submission handler for the module page where modules are enabled, and disabled; every time a module is enable, or disabled, the menu is rebuilt, and both the menu hooks are invoked.