Have you ever worked with a client where you are trying to customize the WordPress back-end experience for them? Maybe you added a custom dashboard widget, removed menu items, or even created custom write panels. Well Greg Kerstin (@graphicagenda) was working on a project where he wanted to modify the howdy text in the WordPress admin bar. Normally it says Howdy, Username. He was kind enough to submit a snippet to us in which he shows how to change the howdy text and replace it with Welcome.
All you have to do is paste the following code in your theme’s functions.php file, or 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, ), ) ); } }
And you are done.
Thank you so much! Worked like a charm!
You’re welcome
Worked, thank you.
You’re welcome
Works like a charm! Many thanks, my friend!
Thank you. It works on mine.
hello can anyone help me?
I want to translate a string in wordpress theme
//
if($mt_o[‘mt_rewrite_doctor_name’]!=””) { $mt_cpt_doctors_name = $mt_o[‘mt_rewrite_doctor_name’]; } else { $mt_cpt_doctors_name = “Staff'”;}
//
i translated such :
if($mt_o[‘mt_rewrite_doctor_name’]!=””) { $mt_cpt_doctors_name = $mt_o[‘mt_rewrite_doctor_name’]; } else { $mt_cpt_doctors_name = __(‘Staff’,’madza_translate’);}
but it does not work!!!!
can you guy help me ? plz plz
It doesnt work,,, after I use this code, wordpress (Version 4.2.2) admin panel cant load,, should remove this code..
There is a much easier way to do this by using the old menu node values:
function np_replace_howdy($wp_admin_bar){
//New text to replace Howdy
$new_text = ‘Welcome’;
//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_account->href,
‘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);
See my gist:
https://gist.github.com/Davidlab/8460a3cec27cb585d95c
it is not woprking in my code . please suggest some easy code to remove howdy with hello
I tried but it didn’t work.. kept saying error and when tried to repair it, my WordPress admin panel couldn’t load any more
I had to switch back to my back up functions.php file (fortunately i had it). Perhaps i made a mistake but it would be nice to have something that is really copy and paste for neophytes like myself with clear instructions instead of expecting everyone to know something else that may be common sense for those who know codes. Gauranga.
Can we make it change each time to say hello in different languages?
Yes, you can. It may be a little complicated but do able. You will need to create an array in PHP with greetings in different languages. Then randomly pick a string from the array and use it with the rest of the code above.
Wow…! Thank you genius..,
Perfect! Thank you.
Hey in the admin panel howdy can be edited but on the front end howdy is still there and cannot be changed so what should i do to edit it?
@senlinonline: That is a great snippet! but it reverts back to the howdy for the frontend admin bar while logged in.
Changing “Howdy” can actually be done quite a bit simpler than the above code. Add this to your functions.php (or functionality.php or any other file): /** CHANGE HOWDY – http://wpmu.org/daily-tip-how-to-change-the-wordpress-howdy-message-to-a-custom-welcome/ **/add_filter(‘gettext’, ‘change_howdy’, 10, 3);function change_howdy($translated, $text, $domain) { if (!is_admin() || ‘default’ != $domain) return $translated; if (false !== strpos($translated, ‘Howdy’)) return str_replace(‘Howdy’, ‘Welcome back’, $translated); return $translated;}/** END CHANGE HOWDY **/
I know, actually had a client ask me if it was made by a southern company because when I was signed it in said ‘howdy’, had a good laugh, but def something to do if your not positive on how a client might react
Sean ‘WordPress Guy’ Vosler for the sake of customization? Not everyone thinks that Howdy is cool. Greg said he will be sending us a more detailed tutorial on how he added more links and such.
Cool Tutorial. Just love it. Thanks! for this
Wow, great tip
why would you want to change this??? :p