Black Friday Sale! Get up to $40 off GP Premium!Learn more

[Resolved] Login/out and register links in submenu

Home Forums Support Login/out and register links in submenu

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

    Hey

    I am using the following snippet to have login/0ut and register links in my main menu.

    ///////////// LOGIN AND REGO /////////////////////////////////
    
    //  LOGINOUT AND REGO LINK IN MAIN MENU 
    
    function add_login_logout_register_menu( $items, $args ) {
     if ( $args->theme_location != 'primary' ) {
     return $items;
     }
     
     if ( is_user_logged_in() ) {
     $items .= '<li><a href="' . wp_logout_url() . '">' . __( 'Log Out' ) . '</a></li>';
     } else {
     $items .= '<li><a href="' . wp_login_url() . '">' . __( 'Login In' ) . '</a></li>';
     $items .= '<li><a href="' . wp_registration_url() . '">' . __( 'Register' ) . '</a></li>';
     }
     
     return $items;
    }
     
    add_filter( 'wp_nav_menu_items', 'add_login_logout_register_menu', 199, 2 );
    
    // END LOGINOUT IN MENU 

    I have too many tab on my navigation and so I would like to put the login/out and Register links as submenu items under a single nav tab called Members.

    What tweaks to the above snippet are required to achieve this.

    Thanks in advance for your help.

    GeneratePress 1.4
    GP Premium 1.4.3
    #375093
    Tom
    Lead Developer
    Lead Developer

    I’m not sure if it’s possible to add sub-menu items using a filter like that.

    You would likely need to use a plugin.

    This is the only one I could find: https://en-ca.wordpress.org/plugins/baw-login-logout-menu/

    It hasn’t been updated in a while, but there’s still 40,000+ people using it.

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