• catcarrot

    (@catcarrot)


    when trying to add login log out button to the main menu it does not work in this theme but has no problem in others that I use
    this is the way I added the buttons:
    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 == ‘primary’) {
    $items .= ‘

    • Log Out
    • ‘;
      }
      elseif (!is_user_logged_in() && $args->theme_location == ‘primary’) {
      $items .= ‘

    • Log In
    • ‘;
      }
      return $items;
      }

Viewing 1 replies (of 1 total)
  • Theme Author TT Themes

    (@tomastoman)

    Hi,

    your code does not work because there is no menu area called “primary” in BrickYard theme. The appropriate slug for the Main Header Menu is “main-navigation”:

    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 == 'main-navigation') {
            $items .= '<li><a href="'. wp_logout_url() .'">Log Out</a></li>';
        }
        elseif (!is_user_logged_in() && $args->theme_location == 'main-navigation') {
            $items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
        }
        return $items;
    }

    Best regards,
    Tomas Toman

Viewing 1 replies (of 1 total)
  • The topic ‘can't modify menus’ is closed to new replies.