Skip to content

Instantly share code, notes, and snippets.

@rutcreate
Created December 20, 2012 01:17
Show Gist options
  • Save rutcreate/4342239 to your computer and use it in GitHub Desktop.
Save rutcreate/4342239 to your computer and use it in GitHub Desktop.
[Drupal 7] How to create custom menu programmatically http://rutcreate.com/how-to-create-custom-menu-programmatically
<?php
$menu = array(
'menu_name' => 'custom-menu',
'title' => t('My custom menu'),
'description' => t('The <em>Custom</em> menu contains links for testing only.'),
);
menu_save($menu);
/**
* Implements hook_install().
*/
function menu_install() {
$system_menus = menu_list_system_menus();
$t = get_t();
$descriptions = array(
'navigation' => $t('The <em>Navigation</em> menu contains links intended for site visitors. Links are added to the <em>Navigation</em> menu automatically by some modules.'),
'user-menu' => $t("The <em>User</em> menu contains links related to the user's account, as well as the 'Log out' link."),
'management' => $t('The <em>Management</em> menu contains links for administrative tasks.'),
'main-menu' => $t('The <em>Main</em> menu is used on many sites to show the major sections of the site, often in a top navigation bar.'),
);
foreach ($system_menus as $menu_name => $title) {
$menu = array(
'menu_name' => $menu_name,
'title' => $t($title),
'description' => $descriptions[$menu_name],
);
menu_save($menu);
}
}
name = My Custom Menu
description = Provide custom menu for testing only
core = 7.x
<?php
/**
* Implements of hook_install().
*/
function my_custom_menu_install() {
$t = get_t();
$menu = array(
'menu_name' => 'custom-menu',
'title' => $t('My custom menu'),
'description' => $t('The <em>Custom</em> menu contains links for testing only.'),
);
menu_save($menu);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment