Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1342362

    Hi team,

    Hope you are doing fine. I had put the following code in functions.php of child theme. Now the issue is that the button is part of the menu and shows on mobile devices only, How do I put this code in correct manner so it will not display as twice on mobile devices. for your reference i am attaching the images for further clarification of issue.

    Enfold theme issue of Login and logout button on Mobile Devices

    // 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 == 'avia') {
            $items .= '<li><a href="https://brbbrothers.com/my-account/customer-logout/">Log Out</a></li>';
        }
        elseif (!is_user_logged_in() && $args->theme_location == 'avia') {
            $items .= '<li><a href="https://brbbrothers.com/my-account/">Log In</a></li>';
        }
        return $items;
    }
    • This topic was modified 3 years, 8 months ago by Yigit.
    #1342421

    Hey tauqer30,
    Thank you for the screenshot, I was able to find your site and found that your custom menu item li doesn’t include the class menu-item
    please include this class and it won’t show on mobile. Your code snippet above didn’t post correctly so I can’t advise on how to adjust it, if you need further help please include an admin login in the Private Content area.

    Best regards,
    Mike

    #1342464

    Sure,

    It’s very helpful. The credentials are included in private content area.

    #1342466

    Hi,
    Thank you for the login, I adjusted your links to have the class menu-item so they only show on desktop
    This is the new code:

    
    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 == 'avia') {
            $items .= '<li class="menu-item"><a href="https://your-site.com/my-account/customer-logout/">Log Out</a></li>';
        }
        elseif (!is_user_logged_in() && $args->theme_location == 'avia') {
            $items .= '<li class="menu-item"><a href="https://your-site.com/my-account/">Log In</a></li>';
        }
        return $items;
    }

    please check.

    Best regards,
    Mike

    #1342705

    Hi Team,

    Thanks for the updated code. The code is working perfectly.

    Many Thanks.

    #1342707

    Hi,
    Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

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