Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Last active May 17, 2025 13:06
Show Gist options
  • Select an option

  • Save yuriinalivaiko/fd6d8b0ef44991a4b94c64284e1cde0e to your computer and use it in GitHub Desktop.

Select an option

Save yuriinalivaiko/fd6d8b0ef44991a4b94c64284e1cde0e to your computer and use it in GitHub Desktop.
Ultimate Member customization. Display custom images in the member directory grid.
<?php
/**
* Display custom images in the member directory grid.
*/
add_filter( 'um_ajax_get_members_data', function( $data_array, $user_id, $directory_data ) {
// List needed fields here.
$fields = array(
'um_image_upload',
'upload_logo',
);
foreach ( $fields as $meta_key ) {
$file_name = um_user( $meta_key );
if ( $file_name ) {
$file_path = trailingslashit( UM()->uploader()->get_upload_user_base_dir( um_user( 'ID' ) ) ) . $file_name;
$file_url = trailingslashit( UM()->uploader()->get_upload_user_base_url( um_user( 'ID' ) ) ) . $file_name;
if ( file_exists( $file_path ) ) {
$data_array[ 'hook_after_user_name' ] .= '<div class="um-photo"><a href="#" class="um-photo-modal" data-src="' . esc_attr( $file_url ) . '"><img src="' . esc_attr( $file_url ) . '" alt="' . esc_attr( $meta_key ) . '"/></a></div>';
}
}
}
return $data_array;
}, 10, 3 );
@yuriinalivaiko
Copy link
Copy Markdown
Author

yuriinalivaiko commented Dec 9, 2024

This code displays the custom image fields in the member directory.
Images are clickable. You'll see an enlarged image in the popup on click.

Add fields you want to display to the $fields array then add this code to the functions.php file in the theme directory.

Expected result

Directory grid
Display custom images in the member directory grid

Popup
Display custom images in the member directory grid (popup)

There is an alternative solution. Read the article Add an image field into the profile card in the member directory.

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