Let me fully describe the problem I am trying to solve as there may be a better way of doing what I am trying to do.

On my Drupal 7 install, when a user is logged out, the Main menu shows Home / Log In and a few other links I've added. This is $primary_nav in the theme.

When a user is logged in, a Log Out link is added.

What is confusing however, is that there is still a login link in the Main menu.

My solution was to create a second menu that would replace the Log in link with a link to the user's account page when they are logged in. All other links would remain the same.

In the template, I am doing the following:

<?php // show different menus depending on if the user is logged in ?>
<?php if ($user->uid): ?>
<?php $menu = menu_navigation_links('user-menu'); ?>
<?php print theme('links__menu_user_menu', array('links' => $menu)); ?>
<?php else: print $primary_nav; ?>
<?php endif; ?>

And this correctly shows the right menu depending on whether the use is logged in or not.

However, the styles are completely different. $primary_nav is a horizontal menu and user-menu is a vertical menu.

According to http://drupal.org/node/254940#theme-suggestions-for-menus, I should be able to create a function in my theme's template.php file and style it. However, I tried doing the following:

function MYTHEME_menu_tree__user_menu(&$variables) {
  echo 'Success'; exit;

But that code is not run.

So my questions are these:

1) Is this the best approach to replace Log In with a link to the user account page when the user is logged in?

2a) If so, what's the best way to get the menu styled the way I want it?

2b) If not, how can I achieve the effect listed in 1)?


1 Answer 1


If you use user as login path, it will visible after login.

You should replace user with user/login it will gone after login.

Also user's profile link is available in User menu, just edit it and change its parent menu to your primary nav.

  • So much simpler than the way I was trying to do it. Thanks! Nov 25, 2012 at 13:57

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.