Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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)?

Thanks!

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
So much simpler than the way I was trying to do it. Thanks! –  lokisapocalypse Nov 25 '12 at 13:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.