[ad_1]
I got fed up with the default ‘Howdy’ message a long time ago but wanted to have something more than just a clients name over in the top right of their screen. It was then that I came up with the following modification.
Professionalism is needed on a clients site and I feel that this would be a well deserved feature to add to ASE.
// Greet user with Good Morning, Afternoon or Evening depending on the time of day
function ctm_replace_howdy( $wp_admin_bar ) {
// Get the current hour
$current_hour = date( 'H' );
// Define the greetings based on the time of day
if ( $current_hour < 12 ) {
$greeting = 'Good Morning';
} elseif ( $current_hour < 18 ) {
$greeting = 'Good Afternoon';
} else {
$greeting = 'Good Evening';
}
// Get the node
$my_account = $wp_admin_bar->get_node( 'my-account' );
// Extract the username from the title
preg_match( '/^(.*),(.*)$/', $my_account->title, $matches );
$username = trim( $matches[2] );
// Construct the new title with the updated greeting
$new_title = $greeting . ', ' . $username;
// Update the title
$my_account->title = $new_title;
// Add the updated node
$wp_admin_bar->add_node( array(
'id' => 'my-account',
'title' => $my_account->title,
) );
}
add_filter( 'admin_bar_menu', 'ctm_replace_howdy', 25 );
