Matthew Purdon
Matthew Purdon

Reputation: 773

Drupal adding external links to custom menus

I am trying to add a custom menu to Drupal 7 but it seems that I am not able to handle external links in hook_menu as they don't get inserted into the database. When I change the implementation to use menu_link_save, internal menu items don't get saved in the menu route table so they don't show up. Is there a way to implement a custom menu that will be displayed in the footer that contains both normal menu items and links to external websites?

Upvotes: 2

Views: 3516

Answers (2)

user1665211
user1665211

Reputation: 21

This is not true, atleast not now.

You can add external items like this

$items['http://facebook.com/'] = array(
  'title' => t('Facebook'),
  'type' => MENU_NORMAL_ITEM,
  'access arguments' => array('access content'),
  'menu_name' => 'menu-footer'
);

Upvotes: 1

Clive
Clive

Reputation: 36965

hook_menu() is really only for internal paths by design and as such external paths don't belong in the menu_router table. There is a little trick you can do to make internal paths that you define immediately redirect to the external site, using drupal_goto() as your page callback:

$items['my_internal_path'] = array(
  'title' => 'Title',
  'type' => MENU_NORMAL_ITEM,
  'access arguments' => array('access content'),
  'page callback' => 'drupal_goto',
  'page arguments' => array('http://external-site.com/')
);

Hope that helps

Upvotes: 6

Related Questions