Welcome Name in Buddypress Admin Bar

This handy snippet allows you to create a function that can be added as an action to "bp_adminbar_menus" and it will place a "welcome, username" or "welcome, guest" in the admin navbar.  i have a couple of css classes to help style the welcome message so there are no arrows for the menu bar, but you can style it how you like. the "15" in the "add_action" just places it to the right of the built in menus of the nav bar.
function add_welcome_message() {
global $current_user;
$author = $current_user->display_name;       
if ( is_user_logged_in() ) {
        echo "<li>Welcome <strong>" . $author . "</strong></li>";
        echo '<li><a href="' . wp_logout_url( site_url() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';                
        } else {
        echo "<li>Welcome <strong>Guest</strong></li>";
add_action( 'bp_adminbar_menus', 'add_welcome_message', 15 );
Post a comment

Real Time Web Analytics ^