I am using ACF to create a place where users can upload a profile image on the back end and then have it show up on their posts on the front end.
I have checked return value to get image url but it keeps pulling in the image ID. I check the source code on the front end and it is just showing the ID. I need the full image url.
Is this a conflict with the user profile page? I am able to get this to work on other pages no problem.
Here is how I am calling it in the theme:
<img src="<?php the_author_meta( 'user_profile_image' ); ?>" />
I think you set your image field to return image ID. There’s two ways you can resolve your problem.
1. Change return value to image url. See link screenshot for Image Field Settings.
2. See code below:
<?php echo wp_get_attachment_image( the_author_meta( 'user_profile_image' ) ); ?>
Thats it, hope I did solve your problem.
So none of those solutions worked but I did find something that did. I used the following code and was able to get the image to finally show up.
<?php $publisher_photo = get_the_author_meta('user_profile_image'); $image_src = wp_get_attachment_image_src($publisher_photo); echo '<img class="avatar" src="'. $image_src .'" />'; ?>
Thank you for your help with this.
I am not sure if your using acf field or wp core because of as far as I know in order to get the value of the acf field you need to use get_field or get_sub_field(if repeater/flexible content).
Then the above function/method “get_the_author_metat()” is a wordpress function. http://codex.wordpress.org/Function_Reference/get_the_author_meta
And this code
<?php echo wp_get_attachment_image( get_field( 'user_profile_image' ) ); ?> will gives you the whole image object with the correct url.
Anyways happy for you to get it working.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2023 Advanced Custom Fields.