Drupal: How to Rebuild Menu Navigation

23,487

Solution 1

Note that although there are options to rebuild the menu (see the other answers), these might or might not work to clean up issues with menu links.

Rebuilding the menu just rebuilds the menu router items and the menu links as far as they are automatically generated based on the menu router items. There are known issues with that, for example re-parenting menu links (http://drupal.org/node/550254). If menu links have been customized or added manually (or Drupal thinks they have been changed.. ), then these will not be touched.

As mentioned in another question already, the tight coupling between these two systems will probably be changed in D8 so that you will have to declare menu links separatly from menu router items.

Solution 2

Here is another option for when you're not able to access the site or do not have Devel or Drush installed. Create a file such as rebuild.php and place it in your Drupal root (though it doesn't matter because chdir will switch to the specified Drupal root). Then after you visit that script it should rebuild the menu's and all should then be well on the site.

<?php
  // Bootstrap
  // Change chdir to the full path of your Drupal root
  chdir('/home/myusername/public_html/');
  define('DRUPAL_ROOT', getcwd());
  require_once './includes/bootstrap.inc';
  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

  // Rebuild
  menu_rebuild();
?>

Solution 3

variable_set('menu_rebuild_needed', TRUE);

Solution 4

I came across the same problem. I switched from MENU_NORMAL_ITEM to MENU_CALLBACK and could not get rid of the menu items in the navigation block. I tried a couple of the solutions above with no success. What worked for me was commenting out my menu items in hook_menu, clearing cache, re-enabling them and clearing cache once again.

This is what I returned in Hook_menu to clear all menu items:

return array(); //$items;

Solution 5

Visiting the modules list page generally rebuilds the menus.

You can also try installing Dev modules Enable the dev block and you have a link for rebuild menus.

Share:
23,487

Related videos on Youtube

Alan Storm
Author by

Alan Storm

Portland based Web Developer/Programmer/Engineer. Projects include No Frills Magento Layout, the only Magento layout book you'll ever need and Commerce Bug, the debugging extension for the Magento Ecommerce system. If you're interested in low cost, in-depth mentoring/tutoring, checkout my Patreon campaign.

Updated on March 16, 2020

Comments

  • Alan Storm
    Alan Storm about 4 years

    In Drupal 7.0, when I change a routing path/menu from the type MENU_NORMAL_ITEM to the type MENU_CALLBACK, Drupal 7.0 does not remove the item from the menu_links table. I'm not sure if this is a bug or not, but I've filed one with the core team.

    With that context in place, is there a way to force Drupal to do a rebuild of all its navigation menus? The bug I've described above is happening even when I clear out Drupal's cache after changing a Menu item.

    I know I can rename an individual menu route, clear cache/refresh, and then name the item back to get any individual route/menu link flushed. I'm looking for a single command I can run (or function to call, or set of commands) and know all the menu navigation is up to date without worrying I've hosed some other part of the system by messing with internals.

    Does this exist? If you're going to mention drush or devel, you're awesome, but specific instructions on those tools are what I'm after.

  • Timofey Drozhzhin
    Timofey Drozhzhin over 11 years
    I don't believe Devel module has an option to rebuild menus in D7. +1 for the script, it works great!
  • mrN
    mrN almost 10 years
    I run this script but its not rebuilding the menu. drupal.stackexchange.com/questions/116443/…
  • mbomb007
    mbomb007 over 4 years
    Or with drush: drush vset menu_rebuild_needed 1

Related