I am using Drupal 7. I have just built a wonderful custom module. Now I need to add it to my main menu, under the parent item "Tools and Resources."

I know I can go to the homepage and click on the little gear and go to "List links", which will take me to admin/structure/menu/manage/main-menu/list?destination=node and I can click-and-hold on the little compass and drag-and-drop my module in the desired place. But, is there a way to do this through the PHP code in the module itself?

1 Answer 1


Menu items are nested using the item path. Take look to the paragraphs module:

 * Implements hook_menu().
function paragraphs_menu() {
  $items = array();
  $items['admin/structure/paragraphs'] = array(
    'title' => 'Paragraph Bundles',
    'description' => 'Manage Paragraph bundles',
    'page callback' => 'paragraphs_admin_bundle_overview',
    'access arguments' => array('administer paragraphs bundles'),
    'file' => 'paragraphs.admin.inc',

  $items['admin/structure/paragraphs/list'] = array(
    'title' => 'List',
    'weight' => -10,

  $items['admin/structure/paragraphs/add'] = array(
    'title' => 'Add Paragraph Bundle',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('paragraphs_admin_bundle_form'),
    'access arguments' => array('administer paragraphs bundles'),
    'type' => MENU_LOCAL_ACTION,
    'file' => 'paragraphs.admin.inc',

  $items['admin/structure/paragraphs/%paragraphs_bundle'] = array(
    'title' => 'Edit paragraph bundle',
    'title callback' => 'paragraphs_bundle_title_callback',
    'title arguments' => array(3),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('paragraphs_admin_bundle_form', 3),
    'access arguments' => array('administer paragraphs bundles'),
    'file' => 'paragraphs.admin.inc',


  return $items;

Also if you want to add your menu item to an existing menu other than administration use the menu key.

$items['menu-item'] = array(
  'title' => 'Foo bar',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('foo_bar'),
  'menu' => 'user_menu'

Check the hook documentation for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.