• Hello everybody, I’m Having a lame issue to display username in main menu.. I been trying since 4 days different plugins, i tried shortcode in menu plugin and widget in menu plugins to display login-logout switcher widget there.. but with no luck.
    here is a link to my website
    https://shamshon.com/test/

    is there a piece of code i can insert somewhere to make it work??

    Would appreciate help please!

Viewing 1 replies (of 1 total)
  • add next function to your function.php file

    function my_custom_menu_item($items, $args)
    {
        if(is_user_logged_in() && $args->theme_location == 'primary')
        {
            $user=wp_get_current_user();
            $name=$user->display_name; // or user_login , user_firstname, user_lastname
            $items .= '<li><a href="">Welcome '.$name.'</a></li>';
            $items.= //Change Password, Logout, etc
        }
        elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
            $items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
            $items.= //Sign up, Lost Password
        }
        return $items;
    }
    add_filter( 'wp_nav_menu_items', 'my_custom_menu_item');
Viewing 1 replies (of 1 total)
  • The topic ‘Make UserName display on top nav menu’ is closed to new replies.