I just want to programmatically add some menu items to the main menu, but none of the answers I found worked. Some answers suggest using hook_menu()
, others suggest using menu_link_save()
. I followed what reported in Can I add a custom link to "Main Menu" via hook_menu? but it just doesn't work. There's no new item added, neither in the UI nor in the database.
function mymodule_menu() {
$items['my/path'] = array(
'title' => 'Title',
'page callback' => 'page_creator_function',
'access callback' => TRUE,
'menu_name' => 'main-menu',
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
Also I found How and where do I programmatically add a menu to the Navigation menu?. Answer #2 says that using menu_link_save()
is the way to go, but I could not get it to work. Do I have to place the code in a certain location or a special hook?
$item = array(
'link_path' => 'my_path',
'link_title' => 'Title',
'menu_name' => 'main-menu',
'weight' => 0,
'language' => 'en',
'plid' => 0,
'module' => 'menu',
);
menu_link_save($item);
Since both answers didn't work out, it seems that I am missing a crucial point. Could anyone say what's going on here?