Add custom tab to Drupal 7 user profile page

I am trying to add two new tabs to the user account page on mysite.com/user on my Drupal 7 site. I want to add links to add node / add / photo photos and add node / add / video video, but the following code is for my module user_menu_add does not work for me:

function user_menu_add_menu() { $items['node/add/photos'] = array( 'title' => t('Add Photos'), 'page callback' => 'user_menu_add', 'page arguments' => array(1), 'access callback' => TRUE, 'access arguments' => array('access user menu add'), 'type' => MENU_LOCAL_TASK, ); return $items; } 

my example here , which works, but only for links under the "/ user" subdirectory

 function my_module_menu() { $items['user/%user/funky'] = array( 'title' => t('Funky Button'), 'page callback' => 'my_module_funky', 'page arguments' => array(1), 'access callback' => TRUE, 'access arguments' => array('access funky button'), 'type' => MENU_LOCAL_TASK, ); return $items; } 

Current User Tabs

+4
source share
2 answers

You can save the node/add/photos menu item as is. You need to keep the formatting of the URL pattern as for user/%user/addphoto so that the tab appears on the user profile page. However, try using drupal_goto() in your new menu item to redirect to the node/add/photos page.

Try the following:

 $items['user/%user/addphoto'] = array( 'title' => t('Add Photos'), 'page callback' => 'drupal_goto', 'page arguments' => array('node/add/photos'), 'access callback' => 'user_is_logged_in', 'type' => MENU_LOCAL_TASK, ); 

Literature:

+6
source

I do not have enough reputation to comment on the answer. Please note that hook_menu requires an untranslated name, indeed, the documentation says:

 "title": Required. The untranslated title of the menu item. 

therefore the code should be

 function my_module_menu() { $items['user/%user/addphoto'] = array( 'title' => 'Add Photos', 'page callback' => 'drupal_goto', 'page arguments' => array('node/add/photos'), 'access callback' => 'user_is_logged_in', 'type' => MENU_LOCAL_TASK, ); return $items; } 
+6
source

All Articles