None of these suggestions so far have worked for me, though I’ve managed to sort it out based on that proposed by @ankitbnl406
It seems that WordPress has finally realised their 19th century cowboy greeting is not favoured this side of the Atlantic. Having managed to replace it for some time, mine started greeting me with the almost as naff “Hi, {username}” as from WP 6.6.1 – I assume this is because I have the British (dare I say ‘proper’) English dictionary installed. (Though I note the header on this page, when logged in, still greets me with “Howdy”.) The following simple code in functions.php does exactly what I want – no need for a plugin:
function replace_howdy( $wp_admin_bar ) {
$my_account = $wp_admin_bar->get_node('my-account');
$title = $my_account->title;
/* Look for a comma separator in $title: if there isn't one, don't do anything, but if there is, split the greeting into two and discard the left half (ie. the comma and all that precedes it). Then prepend the remainder with your chosen greeting, eg. in French it could be 'Bonjour'. This will future-proof it in case WP wants to change the greeting again (though if the comma gets removed, we'll have to think again…)
If you want to keep the comma, use $x instead of $x + 1 below. */
$x = strpos ($title, ',');
if ($x) {
$newtitle = 'Hello' . substr($title, $x + 1 );
$wp_admin_bar->add_node( array(
'id' => 'my-account',
'title' => $newtitle,
) );
}
}
// Set the priority to 10000 or greater to stop PHP errors:
add_filter( 'admin_bar_menu', 'replace_howdy', 10000 );
-
This reply was modified 2 months, 4 weeks ago by stevegs.