WordPress – How to check if user logged in or not?

Often many times, you might be searching for the wordpress code which checks  if the user logged in or not.  Its no brainer and amazingly simple!

There could be at many parts of your site (say in header.php) ,  you want to show only certain links when the user is already registered and logged in like myaccount, logout page.

Here is the code…

<?php
if (is_user_logged_in()) { ?>
<a href="<?php bloginfo("url"); ?>/wp-admin/">My Account</a>
<a href="<?php bloginfo("url"); ?>/wp-login.php?action=logout/">Logout</a>
<?php } ?>

Refer to is_user_logged_in() function in wordpress site.

Similar Posts:

Tags:

Balakrishnan Prabhu

Mr. Balakrishnan Prabhu is the founder of Corpocrat magazine. He is also the founder of Best Citizenships (BC), assisting wealthy individuals with with global citizenship and residency programs in Europe. His other interests are Linux, Machine learning, Wordpress, etc. You can contact him here

  • chris

    Exactly the code I was looking for. I want to show people who are logged in certain links not just the ones the general public see.

  • Now I’m able to to do what I ever wanted before, thanks!

  • Thanks!

  • someone

    Lifesaver! thank ya