hi i am looking to combing to pieces of code into 1 both work but not together keep no matter what i try it keeps crashing the site

 if ($t<"12")
   echo " Have a good morning!  $display_name ";
 else if ($t<"18")
   echo " Have a good afternoon!   $display_name ";
   echo " Have a good evening!   $display_name ";
   } ?>


<?php global $current_user; wp_get_current_user(); ?>
<?php if ( is_user_logged_in() ) { 
 echo 'Welcome Brother: ' . $current_user->user_login . "\n";  } 
else { wp_loginout(); } ?>

other user parameters would be great to swap out


2 Answers 2


I can see two very obvious flaws that might be holding you back.

$t=date("H"); gives you a formatted date as a string while if ($t<"12") and else if ($t<"18") are trying to do maths on words.

Consider $t=(int)date("H"); (force the answer to be a whole number) with if ($t<12) and else if ($t<18) which at least does maths with numbers.


This is the code you're looking for. WordPress has a current_time function that handles this, and then you can add some logic to get the user info.

Edit: this also could be used on page, but I prefer the use of it as a reusable function.

function heyBro(){
        global $current_user;
        if (is_user_logged_in()) {
            $display_name = $current_user->user_login;
            $t = current_time('H');
            $salutation = '';
            if ($t < '12') {
                $salutation = 'morning';
            } else if ($t < '18') {
                $salutation = 'afternoon';
            } else {
                $salutation = 'evening';
            return 'Have a good ' . $salutation . ', ' . $display_name . '!';


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.