Title: Help with conditional link code to display name
Last modified: August 18, 2016

---

# Help with conditional link code to display name

 *  [dotnature](https://wordpress.org/support/users/dotnature/)
 * (@dotnature)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/help-with-conditional-link-code-to-display-name/)
 * I have a conditional link to show login/out and profile depending on if the user
   is logged in or not. What I would like is to show the user’s nickname or id next
   to the logout link, ive tried several bits code to no avail.
    The current code
   I use is
 * >  <?php
   >  global $user_login, ; get_currentuserinfo(); if ($user_login){ echo‘
   > [Logout](https://wordpress.org/support/topic/help-with-conditional-link-code-to-display-name/wp-login.php?action=logout/)
   > <br/> [Profile](https://wordpress.org/support/topic/help-with-conditional-link-code-to-display-name/wp-admin/profile.php?output_format=md)
   > <br/>’
   > ;
   >  } else { echo ‘[Not Registered? Click here!](https://wordpress.org/support/topic/help-with-conditional-link-code-to-display-name/wp-register.php?output_format=md)‘;}
 * Ive tried a lot of different code variations to display the user nickname in 
   the logout link but none work. Heres an example of one them that does not work
 * >  <?php
   >  global $user_login, $user_nickname ; get_currentuserinfo(); if ($user_login){
   > echo ‘[Logout <?php echo $user_nickname ?>](https://wordpress.org/support/topic/help-with-conditional-link-code-to-display-name/wp-login.php?action=logout/)
   > <br/> [Profile](https://wordpress.org/support/topic/help-with-conditional-link-code-to-display-name/wp-admin/profile.php?output_format=md)
   > <br/>’
   > ;
   >  } else { echo ‘[Not Registered? Click here!](https://wordpress.org/support/topic/help-with-conditional-link-code-to-display-name/wp-register.php?output_format=md)‘;}
 * any ideas out there

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

 *  [Joshua Sigar](https://wordpress.org/support/users/alphaoide/)
 * (@alphaoide)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/help-with-conditional-link-code-to-display-name/#post-287113)
 * Make the following adjusment
 * `echo 'Logout ' . $user_nickname . '<br />';`
 *  Thread Starter [dotnature](https://wordpress.org/support/users/dotnature/)
 * (@dotnature)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/help-with-conditional-link-code-to-display-name/#post-287125)
 * thanks thats what i was looking for. Now there’s a formating problem though ,
   whenever I try to add an `<li>` tag to code it breaks, currently is squished 
   up compared to the other menu links.
 * `<div id="page">`
 * <div id="superheader">
    <ul id="topnav"> <li><a href="[http://www.dotnature.com&quot](http://www.dotnature.com&quot);
   id="navHome" title="Home" accesskey="h"><u>H</u>ome</a></li> <li><a href="/#"
   id="navAbout" title="About" accesskey="a"><u>A</u>bout</a></li> <li><a href="/#"
   id="navLinks" title="Links" accesskey="g"><u>L</u>inks</a></li> <li><a href="/#"
   id="navContact" title="Contact Me" accesskey="c"><u>C</u>ontact</a></li>
 * <?php 
    global $user_login, $user_nickname ;  get_currentuserinfo();  if ($user_login){
   echo '<a href="wp-login.php?action=logout">logout ' . $user_nickname . '</a>,
 * <a href="wp-admin/profile.php">Profile</a>'
 * ; 
    }  else {  echo '<a href="wp-register.php">login/register</a>';  }  ?>  </
   li> </ul> </div> <div id="header"> <h1><a href="<?php echo get_settings('home');?
   >"><?php bloginfo(''); ?></a></h1>
 * </div>
    <div id="subheader"></div>
 *  [Dgold](https://wordpress.org/support/users/dgold/)
 * (@dgold)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/help-with-conditional-link-code-to-display-name/#post-287138)
 * I’d like to try this too; dotnature’s code is posting kind of funny here in the
   forum tho. Trying to figure out what’s what
 *  Thread Starter [dotnature](https://wordpress.org/support/users/dotnature/)
 * (@dotnature)
 * [20 years, 5 months ago](https://wordpress.org/support/topic/help-with-conditional-link-code-to-display-name/#post-287160)
 * The top part is just plain html that referances my style sheet for my menu (home,
   about, links, contact, login, etc). The middle part starting with <?php is the
   call to display the conditional link depending on if the user is logged in, displays
   register/login for new users, displays logout(username) and profile for users.
   
   It works fine , there just a cosmetic problem that I will try and tackle tomorrow
   when is shows the logout(username) and profile link, it basically messes everything
   up, maybe a css guru could help out.

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

The topic ‘Help with conditional link code to display name’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [dotnature](https://wordpress.org/support/users/dotnature/)
 * Last activity: [20 years, 5 months ago](https://wordpress.org/support/topic/help-with-conditional-link-code-to-display-name/#post-287160)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
