Support

Account

Home Forums Front-end Issues User field image not displaying

Solving

User field image not displaying

  • Hi there!

    I’m having a little trouble getting the User field to display the image, everything else is working perfectly well and it’s even pulling through the url when i check in the inspector however when i hover over the url i get a popup saying ‘could not load the image’.

    Since everything else it working I’m thinking this might be a gravatar or possibly a browser issue.

    Code snippet included below ::

                  $nomInfo = get_sub_field('staff_member'); ?>
                  
                  <div class="nomination-block col-12 col-md-4 text-center">
                    <h3><?php the_sub_field('nom_ranking'); ?></h3>
                    <img src="<?php echo esc_attr($nomInfo['user_avatar']); ?>" alt="author-avatar" />
                    <h3><?php echo $nomInfo['display_name']; ?></h3>
                    <p><?php the_sub_field('staff_content');?></p>
                  </div>
    

    If anyone has any insight into this I’d be really grateful!

  • This looks like a repeater, are you using the user ID in the if and while part of the repeater call?
    Is the field set to return an array or URL?

    But I think the issue is this:
    <img src="<?php echo esc_attr($nomInfo['user_avatar']); ?>" alt="author-avatar" />
    Should be this:
    <img src="<?php echo esc_url($nomInfo['url']); ?>" alt="<?php echo esc_attr($nomInfo['alt']); ?>" />

  • It’s been 2 years since the question, howver I’d like to share my opinion 🙂

    Try to echo just $nomInfo[‘user_avatar’], it contains tag with all info. So the whole line <img src="<?php echo esc_attr($nomInfo['user_avatar']); ?>" alt="author-avatar" />
    will look just like <?php echo $nomInfo['user_avatar']; ?>
    It worked in my case which looks quite same.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.