How Do I Display a User Image in WordPress?

In order to display a user’s profile photograph in a WordPress site, you will need to set up a custom media uploader. To do this, create a new file in your theme’s functions.php file and add the following code:

add_action(‘init’, ‘display_user_image’); function display_user_image() { if ( !current_user_can(‘manage_options’)) { return; } $media = get_user_media(); if ( !empty($media)) { wp_enqueue_media( $media, array( ‘type’ => ‘image’, ‘url’ => get_permalink($media->ID), ‘width’ => 250, ‘height’ => 250, )); } }

In this code, we first check to see if the current user is able to manage options. If not, we return. Next, we get the user’s media using the get_user_media() function.

If the media is present, we enqueue it using the wp_enqueue_media() function. Finally, we set the type of the media to image and set the dimensions to 250 x 250.