add_filter( 'get_avatar', 'wpmem_ul_my_custom_avatar', 10, 6 ); function wpmem_ul_my_custom_avatar( $avatar, $id_or_email, $size, $default, $alt, $args ) { // What is the custom image field's meta key? // Set this value to match the meta key of your custom image field. $meta_key = "image_test"; // Nothing really to change below here, unless // you want to change the <img> tag HTML. $user = false; if ( is_numeric( $id_or_email ) ) { $user = get_user_by( 'id' , (int)$id_or_email ); } elseif ( is_object( $id_or_email ) ) { if ( ! empty( $id_or_email->user_id ) ) { $id = (int)$id_or_email->user_id; $user = get_user_by( 'id' , $id ); } } else { $user = get_user_by( 'email', $id_or_email ); } if ( $user && is_object( $user ) ) { $post_id = get_user_meta( $user->ID, $meta_key, true ); if ( $post_id ) { $attachment_url = wp_get_attachment_url( $post_id ); // HTML for the avatar <img> tag. This is WP default. // $avatar = '<img alt="' . $alt . '" src="' . $attachment_url . '" class="avatar avatar-' . $size . ' photo" height="' . $size . '" width="' . $size . '" />'; $avatar = sprintf( "<img alt='%s' src='%s' class='%s' height='%d' width='%d' %s/>", esc_attr( $alt ), esc_url( $attachment_url ), esc_attr( "avatar avatar-" . $size . " photo" ), (int) $args['height'], (int) $args['width'], $args['extra_attr'] ); } } return $avatar; }
Not sure what to do with this code?
You're not a "coder" and don't know what to do? Don't worry! Code Snippets are the basic building blocks of WordPress customization, and once you know the basics, they are simple to use.
Here are some free articles to get you started:
- Using Code Snippets from the Site
- The functions.php File
- Create a plugin file for custom functions
- Create a child theme
- Do not modify plugin files!
For "hands on" help, consider a plugin support subscription or the Pro Bundle.