1

In Drupal 7 module development, supposedly by using the hook_menu function, how can I add menu link to the user menu? Here.

I found easily it in the administration but I can't find how to do it programmatically, I haven't found any menu type that would fit this situation. Thanks.

1 Answer 1

1

You could specify the menu_name in the data returned by your hook_menu():

function MYMODULE_menu() {
  $items['example'] = array(
    'title' => 'Example Page',
    'page callback' => 'example_page',
    'menu_name' => 'user-menu', // << Menu name
    'weight' => 12, // << position
    'access arguments' => array(
      'access content',
    ),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

By default, it is added in the Navigation menu.

enter image description here

Sign up to request clarification or add additional context in comments.

5 Comments

Doesn't seem to work to me. I cleared the cache after this but the item won't show. If I want to the menu link to send the user to another page, do i simply put "drupal_goto("url") to the callback function?
Yes, you could do drupal_goto("user") to redirect to the user page.
I've checked and it's working as expected. Could you post your $item please?
Oh, then it doesn't seem to work, the link won't show -- I'll update the post
I'm sorry, I don't know what went wrong before.. So I copied your solution and edited it and now it works! Thank you for your time.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.