Home › Forums › General Issues › Error displaying image
Hello, I’m just creating a custom page template and I have a problem displaying a photo on it. In the ACF field settings as the returned format I used the ‘URL’ option. unfortunately, but it doesn’t work. I send my code below. Can anyone help me ?
<div class="px-lg-4 bits-img-folder">
<img src="<?php the_field('sixth_image');?>" alt="" class="bits-img rounded border bg-white">
</div>
I will add one more information that the technique I use works when they add it in the post template. But why not in the page template anymore?
Is it outputting anything? For example an integer (ID) instead of the URL?
The output value for “src” is empty.
I changed the way to array:
<?php
$image = get_field('sixth_image');
if( !empty( $image ) ): ?>
<div class="px-lg-4 bits-img-folder">
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" class="bits-img rounded border bg-white">
</div>
<?php endif; ?>
And this solution works. But there is another problem I will write about in a moment.
By the way, does the display of photos differ if it belongs to a group?
For the image to appear on the page, I need to update the page twice. This is the second complication.
Yes, if a field is in a group it will be different. See the documentation of group fields https://www.advancedcustomfields.com/resources/group/
Whether a given example works or not works is misleading, because you need to refresh the page twice before the completed fields appear. Additionally, using the group field example, I get two php errors: Illegal string offset ‘url’.
The topic ‘Error displaying image’ is closed to new replies.
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.