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. 🙂