Print custom user fields I want to display a custom field, and i've done it with this code

&lt;?php
 global $user;

 $user_fields = user_load($user-&gt;uid);

 $customfield = $user_fields-&gt;field_navnn['und']['0']['value'];

 print  t("Custom field value is " . $customfield. ' ') ; 
?&gt;


but it dosn't show when im logged out.
Thanks
You are using the global variable $user which represents the logged-in user.


  An object representing the user currently visiting the site.
  
  Contains preferences and other account information for logged-in
  users. When a user is not logged-in, the $user->uid property is set to
  0.


You could use the user id from the URL on the user profile page by calling arg(1).
Here is the possible fix for your code:

&lt;?php
 $uid = arg(1);

 $user_fields = user_load($uid);

 $customfield = $user_fields-&gt;field_navnn['und']['0']['value'];

 print  t("Custom field value is " . $customfield. ' ') ; 
?&gt;


I do not concern with your user profile template. This is just for your code fix.