Hello everybody,

I want to create the primary menu programmatically, can anybody help me ?

Comments

nevets’s picture

When you say "I want to create the primary menu programmatically" do you mean you want to add items to the primary menu or control the look of the primary menu?

jalpa_bhalara’s picture

Hello,

Using hook_menu , it is possible to create a menu or menu item and using 'type' attribute , one can set the type of that menu item e.g MENU_NORMAL_ITEM or MENU_CALLBACK

so at the same way, using hook_menu , is it possible to create a menu item which adds in primary menu
e.g my primary menu name is : BookOrder so can i create a menu item which adds in BookOrder using
hook_menu.

do you have any idea ?

Thank you.

nevets’s picture

The following will work though it depends on how core has implement certain things, as part of defining a menu item you could do

  'pid' => variable_get('menu_primary_menu', 0),

which will set the parent of the given menu item. If there is no primary menu it is assigned to the navigation menu instead (since pid is 0). Also if you plan to contribute the module, it is not good practice to assign menu items to the primary menu by default.

jalpa_bhalara’s picture

yes , this is working.

thanx for your great help.