Monday, December 5, 2011

Customize Your Greeting in Your WordPress Dashboard


Customize Your Greeting in Your WordPress Dashboard
by: Keith

Some people would like to learn web design and have their WordPress dashboard greet them in their preferred language. If you go so far as to customize your dashboard widgets, then why not push it a little further by customizing the dashboard greeting, right?

Good thing there’s an easy way to do it. All you have to do is insert this code in to your theme’s functions.php file, or just create a site plugin.
add_action( 'admin_bar_menu', 'wp_admin_bar_my_custom_account_menu', 11 );

function wp_admin_bar_my_custom_account_menu( $wp_admin_bar ) {
$user_id = get_current_user_id();
$current_user = wp_get_current_user();
$profile_url = get_edit_profile_url( $user_id );

if ( 0 != $user_id ) {
/* Add the "My Account" menu */
$avatar = get_avatar( $user_id, 28 );
$howdy = sprintf( __('Welcome, %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' => $profile_url,
'meta' => array(
'class' => $class,
),
) );

}
}

The text highlighted in yellow is the part that you need to change or edit in the code:
$howdy = sprintf( __('Welcome, %1$s'), $current_user->display_name );

And there you have it! With the above code, once you log back in to your WordPress account, you will then be greeted with the word “Welcome” instead of the usual “Howdy.”

No comments:

Post a Comment