Title: $user_identity problem
Last modified: August 18, 2016

---

# $user_identity problem

 *  Resolved [davey579](https://wordpress.org/support/users/davey579/)
 * (@davey579)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/user_identity-problem/)
 * I use this code in my header:
 *     ```
       <?php {
       	if ( ! is_user_logged_in() )
       		include (TEMPLATEPATH . '/loginform.php');
       	else
   
       $link = '
       <div class="logged_in"><div class="logged_in_content">Logged in as: <?php echo $user_identity; ?>
       <a href="' . get_settings('siteurl') . '/wp-login.php?action=logout">Log out</a></div></div>';
   
       	echo apply_filters('loginout', $link);
       }
   
        ?>
       ```
   
 * But the $user_identity doesn’t work for me. It just doesn’t shows up. What am
   i doing wrong?

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/user_identity-problem/#post-601949)
 * you havent defined what $user_identity is.
 *  Thread Starter [davey579](https://wordpress.org/support/users/davey579/)
 * (@davey579)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/user_identity-problem/#post-601955)
 * Oh, and how can I do that?
 *  [whooami](https://wordpress.org/support/users/whooami/)
 * (@whooami)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/user_identity-problem/#post-601959)
 * well start by explaining why you chose to use it in the first place? I’m going
   to guess you didnt pluck it out of the sky, right?
 * I’ll guess that you saw it in some other code – so look at how they defined it.
 *  Thread Starter [davey579](https://wordpress.org/support/users/davey579/)
 * (@davey579)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/user_identity-problem/#post-601963)
 * I want to show the username of someone who is logged in. I got the code form 
   comments.php:
 *     ```
       <?php if ( $user_ID ) : ?>
   
       <p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">Logout &raquo;</a></p>
   
       <?php else : ?>
       input fields (name, e-mail, website).......
       <?php endif; ?>
       ```
   
 * If I put this code in my header, it shows the input fields, so the code doesn’t
   see that i’m logged in…. I hope someone can help me.
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 8 months ago](https://wordpress.org/support/topic/user_identity-problem/#post-601965)
 * $user_identity is indeed a global, however, in subsections of themes, like header.
   php, you don’t necessarily have access to those globals. The comments template
   gets them for free because, well, it’s the comments template and it tends to 
   use those sort of things. The header, on the other hand, generally doesn’t use
   those and so it doesn’t get them for free. It’s a security thing.
 * Outside of the comments template, the correct way to do this sort of thing is
   like so:
 *     ```
       $user = wp_get_current_user();
       echo $user->display_name;
       ```
   
 * Use the display name whenever you want to display the user name.
 * The `is_user_logged_in()` is also correct for usage in the header, you don’t 
   get the $user_ID global there either.
 * Also note that nothing stops you from using these functions in the comments template
   either. They work perfectly well there and are probably preferable in the long
   run. The $user_* globals are just a convenience for the comments template.
 *  Thread Starter [davey579](https://wordpress.org/support/users/davey579/)
 * (@davey579)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/user_identity-problem/#post-601966)
 * Hmm okay, but how can I put that to my code (I’m not so good with php 😉 ), if
   I use this, it still doesnt work:
 *     ```
       <?php {
       	if ( ! is_user_logged_in() )
       		include (TEMPLATEPATH . '/loginform.php');
       	else
   
       $link = '
       <div class="logged_in"><div class="logged_in_content">Logged in as: <?php $user = wp_get_current_user();
       echo $user->display_name; ?>
       <a href="' . get_settings('siteurl') . '/wp-login.php?action=logout">Logout</a></div></div>';
   
       	echo apply_filters('loginout', $link);
   
       }
   
        ?>
       ```
   
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 8 months ago](https://wordpress.org/support/topic/user_identity-problem/#post-601967)
 * Ahh, I see, you’re trying to assign a link. Slightly different, that.
 * Try this:
 *     ```
       <?php {
       if ( ! is_user_logged_in() ) {
       include (TEMPLATEPATH . '/loginform.php');
       } else {
       $user = wp_get_current_user();
       $link = '<div class="logged_in"><div class="logged_in_content">Logged in as:'.$user->display_name.'<a href="' . get_settings('siteurl') . '/wp-login.php?action=logout">Logout</a></div></div>';
       echo apply_filters('loginout', $link);
       }
       }
       ?>
       ```
   
 *  Thread Starter [davey579](https://wordpress.org/support/users/davey579/)
 * (@davey579)
 * [18 years, 8 months ago](https://wordpress.org/support/topic/user_identity-problem/#post-601968)
 * Ah, thanks man! That works perfect.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘$user_identity problem’ is closed to new replies.

 * 8 replies
 * 3 participants
 * Last reply from: [davey579](https://wordpress.org/support/users/davey579/)
 * Last activity: [18 years, 8 months ago](https://wordpress.org/support/topic/user_identity-problem/#post-601968)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
