0

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.

2 Answers 2

1

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

3
  • +1. Seems we have practically identical answers, and minutes apart! Commented Jan 30, 2012 at 20:27
  • 1
    You are the man, too bad I can't vote you up because of having low reputation Commented Jan 30, 2012 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 Commented Jan 30, 2012 at 23:05
1

$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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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