Home › Forums › Front-end Issues › Getting image url from image ID › Reply To: Getting image url from image ID
@egr103 If you are returning an image ID then what you’re doing should work, try echoing the value to see what’s there. There is one case where it would fail, and that’s if there is no image for ‘large’ and this can happen if the uploaded image is smaller than the dimensions set for ‘large’. In other words, of large is set an 1000×1000 and you upload an image that is 800×800, there will be no large image and WP could be returning nothing.
<?php
$hero = get_field('hero_bg');
$size = 'large';
echo 'IMAGE ID ="',$hero,'" URL = "',wp_get_attachment_image( $hero, $size ),'"';
if( $hero ) { ?>
<div class="c-1 hero bg-image" style="background-image: url('<?php echo wp_get_attachment_image( $hero, $size ); ?>');">
<div class="center-wrapper">
<div class="center">
<h1 class="cheddar"><?php the_title(); ?></h1>
</div>
</div>
</div>
<?php } ?>
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.