atshiftWordPress Plugins Choose a product atshift FieldsUser Profile FieldsFreeform LoginFeed BuilderKOTOTSUGI

Displaying Profile Values

Added fields can be retrieved with helper functions or the WordPress user meta API. Always escape values for the output context.

* In normal use, you rarely need to think about output. These retrieval examples are needed when you display user information on the frontend, such as user lists or site-specific profile pages.

Basic retrieval

Replace your_field_key with the Name set in Field Management. Pass the user ID explicitly so the display target is clear.

Use the helper function

<?php
$value = atshift_upf_get_user_field( 'your_field_key', $user_id );
echo esc_html( $value );
?>

When retrieving directly, custom fields are stored in user meta using _atshift_upf_ followed by the field name.

Retrieve directly with the WordPress API

<?php
$value = get_user_meta( $user_id, '_atshift_upf_your_field_key', true );
echo esc_html( $value );
?>

Output by field type

Text and choices

Text, email, number, select, and radio fields are retrieved as strings. Use esc_html() in normal page content.

Display as text

<p><?php echo esc_html( atshift_upf_get_user_field( 'department', $user_id ) ); ?></p>

Textarea

To preserve line breaks, apply nl2br() after escaping.

Display with line breaks

<p><?php echo nl2br( esc_html( atshift_upf_get_user_field( 'profile_note', $user_id ) ) ); ?></p>

Image

Image fields store an image URL. Use esc_url() when outputting it in a URL attribute.

Profile image

<?php $image_url = atshift_upf_get_user_field( 'profile_image', $user_id ); ?>
<?php if ( $image_url ) : ?>
  <img src="<?php echo esc_url( $image_url ); ?>" alt="">
<?php endif; ?>

Checkbox

A checked value can be treated as 1, and an unchecked value as 0.

Branch by checked state

<?php if ( '1' === (string) atshift_upf_get_user_field( 'show_profile', $user_id ) ) : ?>
  <p>This profile is public.</p>
<?php endif; ?>

WordPress standard fields

Standard fields such as username, display name, email, first name, and last name are retrieved through WordPress user APIs.

Display name and email

<?php
$user = get_userdata( $user_id );

if ( $user ) {
  echo esc_html( $user->display_name );
  echo esc_html( $user->user_email );
}
?>

Display safely for each context

  • Normal text: esc_html()
  • URLs: esc_url()
  • HTML attributes: esc_attr()
  • Allowed HTML only: wp_kses_post()

Profile values may include personal information. Separate fields that can be shown publicly from fields that should stay in the admin area.