Asked 7 years ago
23 May 2017
Views 1205
yogi

yogi posted

Wordpress : how to check user logged in or not ?

How to check user is logged in or not ?


<?php 
if(!is_loggedin()){
?>
 <a href="#"> <span> Log in  </span> </a>
<?php  } else {  ?>
 <a href="#">   <span> Log Out <small>Welcome </small> </span> </a>
<?php } ?>
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

is_user_logged_in () is official function to check whether use is logged in or not in WordPress



<?php 
if(is_user_logged_in()){
    $user = wp_get_current_user();
 ?>   
 <a href="">   <span> Log Out <small>Welcome <?php echo $user->user_login; ?>  </small> </span> </a>
<?php  } else {
  ?> 
<a href=""> <span> Log in  </span> </a>
<?php } ?>
			 


in additional wp_get_current_user() give user detail
for example user_login give username

Post Answer