Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #500051

    Hello Guys,

    On my pre-enfold site I used a code provided by WooThemes to show a log in button in the menu when the user is not logged in and a log out button for when, you guessed it, the user is logged in. The code provided is below (in the functions.php file of my child theme) but nothing happens. Do you have any idea?

    Thanks in advance!

    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-menu') {
            $items .= '<li><a href="'. wp_logout_url() .'">Uitloggen</a></li>';
        }
        elseif (!is_user_logged_in() && $args->theme_location == 'primary-menu') {
            $items .= '<li><a href="'. site_url('wp-login.php') .'">Inloggen</a></li>';
        }
        return $items;
    }
    #500355

    Hey Luc!

    does it work on a default WordPress theme? Please send us a link to the site in question. Make sure to use newest theme and WordPress version.

    Best regards,
    Andy

    #500464

    Hi Andy,

    It works for standard themes, before I used “Inspire”. It worked fine.

    • This reply was modified 9 years, 2 months ago by lmercx.
    #501574

    Hey!

    you are using an old version of the theme. Please upgrade to Enfold v3.2.3.

    Cheers!
    Andy

    #501605

    Hey Andy,

    I’ve updated to the latest version of Enfold v3.3.2 but still no link…

    Any other idea’s?

    Regards Luc

    #502792

    Hi!

    please contact WooCommerce as they know their plugin best and can provide you a precise code for what you need. Try to deactivate all other plugins to check if one is causing this issue.

    Cheers!
    Andy

    #502810

    Hey!

    If your using the WordPress menus in Dashboard > Appearance > Menus then switch it to this.

    
    
    add_filter( 'wp_nav_menu_items', 'add_loginout_link', 40, 2 );
    function add_loginout_link( $items, $args ) {
        if (is_user_logged_in() && $args->theme_location == 'avia') {
            $items .= '<li><a href="'. wp_logout_url() .'">Uitloggen</a></li>';
        }
        elseif (!is_user_logged_in() && $args->theme_location == 'avia') {
            $items .= '<li><a href="'. site_url('wp-login.php') .'">Inloggen</a></li>';
        }
        return $items;
    }

    “avia” is the name for our primary menu area. You can use “avia2” or “avia3” for header and footer menu areas.

    Best regards,
    Elliott

    • This reply was modified 9 years, 2 months ago by Elliott.
    #502861

    Hello Elliot,

    Thanks! This works like a charm. Can I change the order so the search icon is at the end? And the login link one before?

    #502938

    Hi!

    Change this line.

    add_filter( 'wp_nav_menu_items', 'add_loginout_link', 40, 2 );
    

    To this.

    add_filter( 'wp_nav_menu_items', 'add_loginout_link', 5, 2 );
    

    Regards,
    Elliott

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