Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #429602

    Hi,
    I would like to add a login/logout link to my secondary menu but I’m not sure which file to edit, to be able to add it. This is the code I’m trying to add:

    add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
    function add_login_logout_link($items, $args) {
            ob_start();
            wp_loginout('index.php');
            $loginoutlink = ob_get_contents();
            ob_end_clean();
            $items .= '<li>'. $loginoutlink .'</li>';
        return $items;
    }

    I tried adding it to my functions.php but that puts it on the secondary AND main menu, but I would like it only on my secondary menu, does anyone know how to do that?

    I was also told to try this code:

    add_filter('wp_nav_menu_items','my_login_func', 10, 2);
         
    function my_login_func($nav, $args) {
              ob_start();
              wp_loginout('index.php');
              $loginoutlink = ob_get_contents();
              ob_end_clean();
         
              if( $args->theme_location == 'NAME OF MENU HERE' ) {
                      $nav .= '<li>'. $loginoutlink .'</li>';
              }
         
              return $nav;
      }
         
    ?>

    I’m meant to replace “NAME OF MENU HERE” with the name of the secondary menu but I’m not sure what it’s called under the Enfold theme. I’ve tried “Secondary Menu” and no luck.

    Any help is appreciated, thanks!

    Thanks.

    • This topic was modified 9 years, 7 months ago by shoo.
    #430383

    Hi shoo!

    I think it should be either, “avia”, “avia2”, or “avia3”. Probably “avia2” if your wanting the secondary menu.

    Cheers!
    Elliott

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.