PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites: Drupal 7 - add link into menu programmatically using hook_menu()

16 Dec 2015

Drupal 7 - add link into menu programmatically using hook_menu()


     This blog describes about how to add a new menu item into menu like main menu, user menu in drupal 7.


drupal 7 - add link into menu programmatically using hook_menu()

     
We can create a menu item using hook_menu in drupal 7. Can we add menu item into already created menu in drupal7? Yes you can add a link into menu using hook_menu().

Add new menu item into main menu in drupal 7:


       Consider below program to add new menu item into main menu in drupal 7.

/**
 * Implement hook_menu()
 */
function phponwebsites_menu() {
  $items['sample'] = array(
    'title' => t('Sample page'),
    'type' => MENU_NORMAL_ITEM,
    'menu_name' => 'main-menu',
    'page callback' => 'samplepage',
    'access callback' => TRUE,
  );

  return $items;
}

/**
 * Implement samplepage()
 */
function samplepage() {
  $str = t('Hi this is sample page');
  return $str;
}


Where,
     type – MENU_NORMAL_ITEM
     menu-name – name of the menu to add new link
  
     You need to clear cache to see created new menu item in main menu. Now i’ve hope you know how to add new link programmatically to already created menu in drupal 7.

6 comments:

  1. Thanks for the tutorial. It really works!

    ReplyDelete
  2. Would far past anybody's doubts have the decision to make on faint spot interests! Welcome to here you'll observe how it should look. dark0de market link

    ReplyDelete
  3. Well… I discharge up web diaries on an on an amazingly boss level disturbing from issue, at any rate I never visited your blog. I added it to populars other than i'll be your experiencing beating. dark0de market url

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. In any case, a website stays an interest in time and cash. onohosting.com/

    ReplyDelete
  6. Ask your SEO Organization what methods they utilize for social occasion backlinks.
    www.ryancameron.me

    ReplyDelete