Hide and show div depending on login

I know I'm around, but I can't seem to get this to work. I am creating my own login navigation and "My Profile". I am using Wordpress code <?php wp_loginout(); ?>

for login / logout and it works fine. Right next to this I have the words "My Profile" and I need to show and hide this based on the login state. If they are logged in, it appears, if not, then it is not displayed.

I found this thread and tried the code, but it doesn't seem to work.

Here is the code I used from this thread:

    <?php if ($user_is_an_admin): ?>
<div id='admin'>
      My Profile
</div>
<?php endif; ?>

      

I realize this is only shown if the person logging in is ADMIN, but I thought I'd try first to see if I can get it to work and then look into the login code or not ...

So, to interrupt the chase, I need to know what code will show / hide "My Profile" depending on the weather in which the person is registered or not. Regardless of the permission settings.

+3


source to share


3 answers


Google Is Your Friend, Quick Search for "Wordpress Login Status"

Yield: http://codex.wordpress.org/Function_Reference/is_user_logged_in

So, a combination of some of the features on this page, I offer you this copy and paste example.



<?php if (is_user_logged_in()): ?>
<div id="user">
      My Profile
</div>
<?php elseif (is_admin()): ?>
<div id="admin">
      Admin Profile
</div>
<?php else: ?>
<div id="login">
      Login...
</div>
<?php endif; ?>

      

Your greeting, p

+3


source


$ user_is_an_admin is a dummy variable and doesn't actually do anything.

What are you looking for in WordPress: is_user_logged_in () ': http://codex.wordpress.org/Function_Reference/is_user_logged_in



<?php if (is_user_logged_in()): ?>
<div id='admin'>
      My Profile
</div>
<?php endif; ?>

      

+1


source


All you need is: http://codex.wordpress.org/Function_Reference/is_user_logged_in

And use the following code:

<?php if(isset(is_user_logged_in()))
{ 
?>
<div id='admin'>
      Show or Hide Content
</div>
<?php 
}
 ?>

      

0


source







All Articles