Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

mattradford commented Aug 12, 2014

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