Home › Forums › General Issues › Image field used in template not always returning image url
Hi,
I’m using an image custom field named “featured_header_image” with return value set to url and its being outputted in my page.php template. So each page has a different header image.
the issue is some pages are working and returning the image url but others are just returning the page url. not sure whats happening with it.
context wise, this piece of code is not within a loop, but i assumed as it was pulling information from each page it should find image field from each page and pull that image in.
the site is currently only on local host so i can’t give you a link to the site.
can anyone help?
here is the code:
<?php get_header(); ?>
<div class=”parallax-bg medium-parallax-bg” data-stellar-background-ratio=”0.4″ style=”background-image: url(<?php the_field(‘featured_header_image’); ?>)”>
<div class=”texture”></div>
</div>
on a page which does work with the image the code outputted looks like this:
<div class=”parallax-bg medium-parallax-bg” data-stellar-background-ratio=”0.4″ style=”background-image: url(http://localhost:8888/christophergladwell/wp-content/uploads/2015/09/VN_VARKALA_013.jpg); background-position: 0% 0%;”>
<div class=”texture”></div>
</div>
on other pages it gets returned like this:
<div class=”parallax-bg medium-parallax-bg” data-stellar-background-ratio=”0.4″ style=”background-image: url(http://localhost:8888/christophergladwell/retreats/); background-position: 0% 0%;”>
<div class=”texture”></div>
</div>
—- Versions —-
ACF v4.4.3
WP v4.3

i had a problem once when the name was too long, maybe try something like “fdhder_img”. i don’t really think that helps but in one case something like this solved the problem for me.
or try
<?php echo get_field('featured_header_image'); ?>
or
<?php echo get_field('fdhder_img'); ?>

Since your code is not in the loop it might also be a good idea to send the page ID along with it.
<?php global $post; ?>
<div class="parallax-bg medium-parallax-bg" data-stellar-background-ratio="0.4" style="background-image: url(<?php echo get_field('featured_header_image', $post->ID); ?>)">
The topic ‘Image field used in template not always returning image url’ 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.