How to Add Time-Based Greeting to Admin Bar
Hey there, WordPress friends! Want to make your WordPress admin bar feel a bit more personal and welcoming? With a simple tweak, you can replace the default “Howdy” greeting with something that changes based on the time of day, like “Good morning, Milan” or “Night owl, Sarah” for those late-night workers. It’s a small touch that adds a warm, friendly vibe to your dashboard. Let’s walk through how to do it with a quick code snippet that’s easy to set up and fun to use.
// Add a Time-Based Greeting to Your WordPress Admin Bar
function wordpress_time_based_admin_greeting( $wp_admin_bar ) {
// Get current hour in 24-hour format
$hour = current_time( 'H' );
// Determine greeting based on time of day
if ( $hour >= 5 && $hour < 12 ) {
$greeting = 'Good morning,';
} elseif ( $hour >= 12 && $hour < 17 ) {
$greeting = 'Good afternoon,';
} elseif ( $hour >= 17 && $hour < 22 ) {
$greeting = 'Good evening,';
} else {
$greeting = 'Night owl,';
}
$my_account = $wp_admin_bar->get_node( 'my-account' );
$wp_admin_bar->add_node(
array(
'id' => 'my-account',
'title' => str_replace( 'Howdy,', $greeting, $my_account->title ),
)
);
}
add_filter( 'admin_bar_menu', 'wordpress_time_based_admin_greeting', 25 );How the Code Snippet Works & What to Expect
This little snippet does something pretty cool: it checks the current time on your WordPress site and swaps out the standard “Howdy” greeting in the admin bar for something that matches the time of day. Here’s the breakdown:
- Time-Based Greetings: The code looks at the hour (in 24-hour format) using WordPress’s current_time function. Depending on the time, it picks one of four greetings:
- 5:00 AM–11:59 AM: “Good morning, [Your Name]”
- 12:00 PM–4:59 PM: “Good afternoon, [Your Name]”
- 5:00 PM–9:59 PM: “Good evening, [Your Name]”
- 10:00 PM–4:59 AM: “Night owl, [Your Name]” (a fun nod to those burning the midnight oil!)
- Personal Touch: The greeting keeps the user’s display name, so it feels personal. For example, if your name is Milan and it’s 8 AM, you’ll see “Good morning, Milan” in the top-right corner of your admin bar.
- Easy to Customize: Want to change the greetings or time ranges? You can tweak the $greeting values or the hour ranges in the code. For instance, swap “Night owl” for “Midnight maestro” if you’re feeling extra creative!
Once you add this code, you’ll notice the admin bar greeting change based on when you’re working. If you log in early, it’ll wish you a good morning. Pulling an all-nighter? You’ll get a friendly “Night owl” vibe. It’s a small way to make your WordPress dashboard feel more like home, whether you’re a morning person or a night shift rockstar.
Give it a try, and let your admin bar greet you like an old friend, no matter the hour. Want to make it even more unique? You can play with the greetings to match your style.
Written by Milan on 10th July 2025

