I'm trying to create a custom author field, the user will past his profile image url. and replace his avatar which displayed in comments.

the field :

function custom_avatar_img($profile_fields) {
$profile_fields['thecustomavatar'] = __('Your Profile Image','mytheme');

    return $profile_fields;
add_filter('user_contactmethods', 'custom_avatar_img');

to replace gravatar:

add_filter( 'get_avatar', 'cyb_get_avatar', 10, 5 );
function cyb_get_avatar( $avatar = '', $id_or_email, $size = 96, $default = '', $alt = '' ) {
$avatar_img = get_the_author_meta('thecustomavatar');
    // Replace $avatar with your own image element, for example
     $avatar = "<img alt='$alt' src='".$avatar_img."' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";

    return $avatar;


it worked but it displaying only the author image in all comments even he isn't the comment poster. I think get_the_author_meta('thecustomavatar') isn't the right way. So, how to get the comment poster custom image field content ?!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.