Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a plugin that outputs username after login, I want it to display first name instead. Here is the code that does it.

        global $userdata,$user_identity;
        get_currentuserinfo();

        if ($userdata->ID>0) {
            // User is logged in
            echo '<div class="login">' . $before_widget . $before_title . "Welcome ".$user_identity . $after_title . '</div>';
            echo '
                <ul class="login-links">
                    <li><a href="'.get_bloginfo('wpurl').'/wp-login.php?action=logout&amp;redirect_to=http://'.$_SERVER["SERVER_NAME"].$_SERVER['REQUEST_URI'].'">Logout</a></li>
                    <li><a href="'.get_bloginfo('wpurl').'/wp-admin">Dashboard</a></li>
                    <li><a href="'.get_bloginfo('wpurl').'/wp-admin/profile.php">Profile</a></li>

                </ul>
            ';
        } else {
        // User is NOT logged in!!!
                echo $before_widget . $before_title . '<div class="login">Welcome Guest, <a href="'.get_bloginfo('wpurl').'/wp-admin">Login</a></div>' . $after_title;

$user_identity is what outputs that username I searched through wordpress forums and someone said I have to add $current_user->first_name to the code. The question is, where and how do I add it? I assume I would need to add it to this line global $userdata,$user_identity; But how do I properly syntax that? I tried doing this but getting syntax errors global $userdata,$user_identity = $current_user->first_name;

Your help is highly appreciated.

share|improve this question
add comment

2 Answers 2

Change global $userdata,$user_identity; to global $userdata, $current_user, $user_identity;

Then change

echo '<div class="login">' . $before_widget . $before_title . "Welcome ".$user_identity . $after_title . '</div>';

to

echo '<div class="login">' . $before_widget . $before_title . "Welcome ".$current_user->user_firstname . $after_title . '</div>';

You can see all the info in the codex : http://codex.wordpress.org/Function_Reference/get_currentuserinfo

share|improve this answer
    
+1. Seems we have practically identical answers, and minutes apart! –  Stephen Harris Jan 30 '12 at 20:27
    
You are the man, too bad I can't vote you up because of having low reputation –  Ben Bibikov Jan 30 '12 at 21:22
    
You can mark the answer as accepted answer. So that the system knows this question is answered. See the FAQ wordpress.stackexchange.com/faq#howtoask –  Rob Vermeer Jan 30 '12 at 23:05
add comment

$user_identity uses the 'Display name publicly as' option on the user's profile page to decide what to display. So you can edit there.

Alternatively, to always display the first name, you can use the global $current_user: to get the first name:

$current_user->user_firstname

See the Codex

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.