Login/Logout and user welcome in WordPress

We should welcome the users on our site to make them comfortable and also to enhance the design of our site. Insert this code to add a login/logout message. Paste the code in the function.php file in the child theme.

<div id="user-details">
<?php
   if (is_user_logged_in()) {
      $user = wp_get_current_user();
      echo 'Welcome back <strong>'.$user->display_name.'</strong>!';
   } else { ?>
      Please <strong><?php wp_loginout(); ?></strong>
      or <a href="<?php echo get_option('home'); ?>/wp-login.php? 
      action=register"> <strong>Register</strong></a>
<?php } ?>
</div>

In the above code first, we are checking if the user is login or not if yes then in the IF block we are printing the login message and if no then in the ELSE block we are printing the logout message.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top