Change the link of ‘Howdy’ at the top right

I’d like to change where the ‘Howdy’ link gets you when you click on it.

I have a website with buddypress and instead of getting users to their profile page I want to get them to their ‘Activity’ tab.

Read More

How can I change the link?

Thanks,
Kat

Related posts

2 comments

  1. It’s not well documented, but the add_node and add_menu methods of the WP_Admin_Bar class can be used not only to create new menu or nodes, but also to update an existing menu or node.

    So i went ahead and tracked down the code that WordPress initially uses to create that item in the admin bar, replicated it, then made adjustments to the Howdy text and used an example link to google. Simply make your own adjustments as appropriate to the example code.

    Example code:
    Update the user account menu in the admin bar

    function wpse_98066_before_admin_bar_render() {
    
        global $wp_admin_bar;
    
        if( !method_exists( $wp_admin_bar, 'add_menu' ) )
            return;
    
        $user_id      = get_current_user_id();
        $current_user = wp_get_current_user();
        $my_url       = 'http://www.google.com';
    
        if ( ! $user_id )
            return;
    
        $avatar = get_avatar( $user_id, 16 );
        $howdy  = sprintf( __('Hey, nice to see you again, %1$s'), $current_user->display_name );
        $class  = empty( $avatar ) ? '' : 'with-avatar';
    
        $wp_admin_bar->add_menu( array(
            'id'        => 'my-account',
            'parent'    => 'top-secondary',
            'title'     => $howdy . $avatar,
            'href'      => $my_url,
            'meta'      => array(
                'class'     => $class,
                'title'     => __('My Account'),
            ),
        ) );
    }
    add_action( 'wp_before_admin_bar_render', 'wpse_98066_before_admin_bar_render' );
    

    I hope that helps, have fun. 🙂

  2. Here is a easier and cleaner way…call the node needed and use the part needed and replace what you want to update

    function np_replace_howdy($wp_admin_bar){
    
    //New text to replace Howdy
    $new_text = 'Welcome';
    $my_url       = 'http://www.google.com';
    
    //Call up the 'my-account' menu node for current values.
    $my_account = $wp_admin_bar->get_node('my-account');
    
    //Replace the 'Howdy' with new text with string replace
    $new_title = str_replace('Howdy', $new_text, $my_account->title);
    
    //Rebuild the menu using the old node values and the new title.
    $wp_admin_bar->add_menu(array(
        'id'     => $my_account->id,
        'parent' => $my_account->parent,
        'title'  => $new_title,
        'href'   => $my_url,
        'group'   => $my_account->group,
        'meta'   => array(
            'class' => $my_account->meta['class'],
            'title' => $my_account->meta['title'],
        ),
     ));
    }
    
    add_action('admin_bar_menu', 'np_replace_howdy', 999);
    

Comments are closed.