Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display Username is Custom Nav Menu item

  • Avatar of damienoneill2001
    damienoneill2001
    Participant

    @damienoneill2001

    Hi all,

    I want to add a piece of code to display some text saying “Welcome, username” in the WordPress Menus. This will only display when a Buddypress user has logged in and it links them to their profile page.

    So far, I have this in my function.php:

    // Filter wp_nav_menu() to add profile link
        add_filter( 'wp_nav_menu_items', 'my_nav_menu_profile_link',10,2 );
        function my_nav_menu_profile_link($menu, $args) {      
                if( is_user_logged_in() && $args->theme_location == 'header2' ){
            $profilelink = '<li>Welcome, <a href="' . bp_loggedin_user_domain( '/' ) . '">' . bp_loggedin_user_id() . '</a></li>';
            $menu = $menu . $profilelink;
        }
        return $menu;
        }

    This works for everything but the Username.

    It is currently displaying the user ID correctly – obviously because the code states bp_loggedin_user_id() – but anything else I try doesnt work. Most terms just leave the space blank and all it returns is “Welcome, ”

    If I use bp_loggedin_user_username(), the username displays, but it breaks out of the code and places itself outside of the tags.

    I hope someone can help.

    Thanks

    Damien

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.