Skip to content

Instantly share code, notes, and snippets.

@mattradford
Created August 12, 2014 23:28
Show Gist options
  • Save mattradford/6941c242a4ff1aa4fd93 to your computer and use it in GitHub Desktop.
Save mattradford/6941c242a4ff1aa4fd93 to your computer and use it in GitHub Desktop.
WordPress - custom user photo from user login name (via custom field)
<?php
$username = get_sub_field('team_member_username');
$the_user = get_user_by('login', $username);
$the_user_id = $the_user->ID;
$user_photo = get_user_meta($the_user_id, 'your_photo', true);
$image_src = wp_get_attachment_image_src($user_photo);
echo '<img class="author-picture" src="'. $image_src[0] .'" />';
?>
@mattradford
Copy link
Author

I wanted to display a user's profile photo (a custom field) on a team page. They are now able to enter their login name, and it will display their photo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment