WordPress.org

Support

Support » How-To and Troubleshooting » Help with conditional link code to display name

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<br/>
    Profile<br/>’

    ;
    }
    else {
    echo ‘Not Registered? Click here!‘;
    }

    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 ?><br/>
    Profile<br/>’

    ;
    }
    else {
    echo ‘Not Registered? Click here!‘;
    }

    any ideas out there

Viewing 4 replies - 1 through 4 (of 4 total)
  • Make the following adjusment

    echo 'Logout ' . $user_nickname . '<br />';

    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" 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>

    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

    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.