Random User Greeting

Looking to give your users a fun and unique greeting?

This function outputs a random greeting along with the logged-in username.

php
function tct_hello_user(){ if ( is_user_logged_in() ) { $morning = array('morning matey','Top of the morning'); $afternoon = array('Afternoon','How was lunch'); $evening = array('You should be asleep','Sleep well'); $hour = date('H'); $username = wp_get_current_user()->user_login; if($hour < 12){ $random = array_rand($morning); return $morning[$random] .' ' . $username; } elseif($hour > 11 && $hour < 18){ $random = array_rand($afternoon); return $afternoon[$random] .' ' . $username; } elseif($hour > 17){ $random = array_rand($evening); return $evening[$random] .' ' . $username; } }}

👋🏻 Weekly Tutorial Digest

I send out a weekly newsletter with links to new tutorials written in the last week, you can subscribe below.

🔒I won't send you spam, I promise