Home Forums Front-end Issues ACF User field – user_avatar conflict


ACF User field – user_avatar conflict

  • When following your documentation to display an ACF user field front end, there appears to be an problem.

    If I use:

    <img src="<?php echo esc_attr($user['user_avatar']); ?>" alt="author-avatar" />

    the browser returns a 404 error because it is attempting to show the following:

    <img src="<img alt='' src='http://tournamentmatchplay.local/wp-content/uploads/avatars/8/5ffa35c9ca85c-bpthumb.jpg' srcset='http://tournamentmatchplay.local/wp-content/uploads/avatars/8/5ffa35c9c6d31-bpfull.jpg 2x' class='avatar avatar-96 photo' height='96' width='96' loading='lazy'/>" alt="author-avatar">

    If I use:

    <?php echo $opponentA['user_avatar']; ?>

    it WILL show it front end, but I am unable to assign my own attributes to it.

    I’m sure this is not theme related or a conflict as I’ve tried it with wordpress 2021 theme and only acf plugin activated. I’ve tried many ways to show this in the front end. I’m still a novice at PHP, so if I’m doing something wrong, please let me know.

  • $user['user_avatar'] contains the entire image tag. You are echoing that entire image tag inside of the src for another image.

    echo $user['user_avatar'];
  • @hube2 thanks John.

    Yes. I recognise that.
    I’m not knowledgeable enough to figure out how to have

    echo $user[‘user_avatar’]

    return just the location (or src attribute) of the image instead of the entire element, which is breaking the code. I’ve copied it directly from the ACF docs, so I would assume it would have worked as advertised. Any ideas?

  • what document did you copy this from?

    It could be that this documentation is wrong.

  • The documentation is wrong.

    That value is the value returned by get_avatar() which is an image tag.

    For more information on using avatars I would suggest looking at the WP documentation.

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

You must be logged in to reply to this topic.