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

I got this code to insert menu bar in the PRIMARY menubar, but I can not find a way to insert it into my secondary, or top menubar above the primary menu bar. Could anyone teach me how to do that?

add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
    if (is_user_logged_in() && $args->theme_location == 'menu_top') {
      $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
    }
    elseif (!is_user_logged_in() && $args->theme_location == 'menu_top') {
      $items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
    }
    return $items;
}

=============Additional Info============== I am using Custom Community Theme 1.4. Just in case it will be helpful, and I tried to use 'menu_top' as keyword rather than primary, but it does not work, it originally was primary!

==============MORE INFO==================== Ok, in request, I found more info, but as I tried, menu_top does not work, and seem these code already tell what is the name of the menu, is that right?

// This theme uses wp_nav_menu() in one location.
    register_nav_menus(array(
        'menu_top' => __('Header top menu', 'cc'),
        'primary' => __('Header bottom menu', 'cc'),
    ));
share|improve this question
    
never mind, I realized that its due to the fact the theme will ROLL back to certain ...place that menu will not display unless there is at least 1 item setup in the menus. –  Adam Mar 8 '13 at 20:11

1 Answer 1

"PRIMARY" and "secondary" menu bar really don't mean anything when used out of context and without explanation. However, (guessing a lot) if your menus are constructed consistently you should be able to find the 'name' of the second menu and add a condition like (overly formatted for readability):

if (
  is_user_logged_in() 
  && (
    $args->theme_location == 'menu_top' 
    || $args->theme_location == 'other_menu_name'
  )
) { 
    $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';

Same with the elseif.

Look for a call to wp_nav_menu in your theme files to find the 'name' of the second menu.

share|improve this answer
    
I added more info, sry for letting you guess so much lol, but I do not konw why the name is not working when I use them, though. –  Adam Mar 8 '13 at 15:58

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.