Displaying First and Last Name instead of Username

stevenandwes - June 16, 2009 - 15:04

Hello everyone,

I am a drupal, php, newbie working in a summer internship and my boss is having me make some changes to our site.

I am trying to get an internal company website to display a users real name instead of the username. Essentially my boss wants it to always say "Welcome! first_name last_name" at the top of the page.

So far I've edited the page.tpl.php file to look like this.

print $site_html . '' . ' Welcome! ' . $user->name . '

' ;

that puts a "Welcome! user_name" right where I want it.

After that I edited the personal information page to include a profile_first and profile_last so the user has to enter their first and last name.

I'm trying to replace the "user_name" with "profile_first", but when I do nothing is displayed, and I get the feeling I'm going about this the wrong way.

Any help would be great thanks.

Have you looked at the

nevets - June 16, 2009 - 16:05

Have you looked at the Realname module?

<?phpglobal $user;$userId =

samwich - June 16, 2009 - 16:54

<?php
global $user;
$userId = $user->uid;
profile_load_profile($user);
$firstName = $user->{profile_first};
$lastName= $user->{profile_last}; ?>

<?php print $firstName; . ' ' . $lastName; ?>

something like that should work to print the name of the logged in user. That's how I used it, although I was using the content profile module to define custom fields for the user.

Thanks Much!

stevenandwes - June 16, 2009 - 17:34

We are looking into the RealName module but for now we are just going to use the code that samwich provided, its simple and most importantly is working. Thanks a bunch everyone.

 
 

Drupal is a registered trademark of Dries Buytaert.