{"id":816,"date":"2014-08-02T06:00:46","date_gmt":"2014-08-02T06:00:46","guid":{"rendered":"http:\/\/www.advancedwebhelp.com\/blog\/?p=816"},"modified":"2014-08-02T06:07:33","modified_gmt":"2014-08-02T06:07:33","slug":"drupal-7-secret-to-using-hook_menu_alter","status":"publish","type":"post","link":"https:\/\/www.advancedwebhelp.com\/blog\/2014\/drupal-7-secret-to-using-hook_menu_alter","title":{"rendered":"Drupal 7: Secret to using hook_menu_alter"},"content":{"rendered":"<p>Are you trying to use hook_menu_alter in Drupal 7 and finding that hook_menu_alter is not appearing to have any effect?    There is a reason.  Hook_menu_alter is not called every time you run your site.   Hook_menu_alter only runs when the menu module is initialized or a menu is initially constructed.   If you have an existing menu and you would like hook_menu_alter to affect that menu, you must do a menu rebuild.   In theory, there are two trivial ways to do this.  However, the 2 trivial methods may not work for you.   The trivial methods are:<\/p>\n<ul>\n<li>Use Devel module option to request menu rebuild<\/li>\n<li>Use drush to request menu rebuild<\/li>\n<\/ul>\n<p>However, these 2 methods may not be convenient for you.   I know that right now (8\/2\/2014), Devel will not run correctly on my install because there appears to be problem with the current combination of devel, devel_theme &#038; simplehtmldom that is currently available seem to crash my install.  At the same time, drush is inconvenient for the install I have available.   My solution involved creation of a simple file that will force the menu rebuild.<\/p>\n<p>To do a menu rebuild programattically:<\/p>\n<ul>\n<li>Create a file in your site&#8217;s base directory, perhaps menuRebuild.php<\/li>\n<li>Include the following code in the new file\n<pre><code>\r\n  &lt;?php\r\n  \r\n    chdir(\"&lt; your-root-directory &gt;\") ;\r\n    define(\"DRUPAL_ROOT\", getcwd());\r\n    require_once(\".\/includes\/bootstrap.inc\") ;\r\n    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL) ;\r\n    \/\/ Rebuild\r\n    menu_rebuild() ;\r\n    echo \"rebuilt\" ;\r\n\r\n  ?&gt;\r\n\r\n<\/code><\/pre>\n<\/li>\n<li>run the file &#8230; the menu will be built.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Are you trying to use hook_menu_alter in Drupal 7 and finding that hook_menu_alter is not appearing to have any effect? There is a reason. Hook_menu_alter is not called every time you run your site. Hook_menu_alter only runs when the menu module is initialized or a menu is initially constructed. If you have an existing menu [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,12,5],"tags":[],"class_list":["post-816","post","type-post","status-publish","format-standard","hentry","category-drupal","category-drupal-modules","category-php"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/posts\/816","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/comments?post=816"}],"version-history":[{"count":2,"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/posts\/816\/revisions"}],"predecessor-version":[{"id":820,"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/posts\/816\/revisions\/820"}],"wp:attachment":[{"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/media?parent=816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/categories?post=816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.advancedwebhelp.com\/blog\/wp-json\/wp\/v2\/tags?post=816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}