Tagged: , ,

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #531722
    #532637

    Hi there, can anyone help me with this? I see all posts before and after mine have been answered except mine.

    Thank you.

    #533437

    Hey!

    I didn’t test your code out but just from looking at it you’ll need to change the “top-menu” part to point to our theme location names.

    You can change it to this to target the primary menu.

    if (is_user_logged_in() && $args->theme_location == 'avia') {
    

    Or switch it to “avia2” or “avia3” to target the header / footer menu areas.

    Best regards,
    Elliott

    #533492

    Hi Elliott,

    Thanks for getting back to me. This is exactly what I was missing! Works perfectly now. Thank you.

    In case anyone else is trying to add sign in/sign out logic to their header that uses non WP default pages (like with a WooCommerce store) via the functions.php file, here’s the code:

    // Add Log in / log out links to top menu
    
    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 == 'avia2') {
            $items .= '<li><a href="your-domain/account/customer-logout/">Log Out</a></li>';
        }
        elseif (!is_user_logged_in() && $args->theme_location == 'avia2') {
            $items .= '<li><a href="your-domain/account/">Log In</a></li>';
        }
        return $items;
    }

    This will add the links to the top menu in your theme. Just replace the URL’s with your own URL’s to your log in and log out pages.

    #535402

    Hey!

    glad it’s working for you and thanks a lot for sharing!

    Cheers!
    Andy

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Add Login / Log out links to top menu’ is closed to new replies.