I am trying to use ACF to put an image on one of my template pages. I did a var_dump of my variable and the data is there. Why is my image not showing up? I tried wrapping it in an tag but that didn't return anything. Any suggestions?
<?php
$first_img = get_field('image_first');
?>
<div class="panel--standard">
<div class="container container__grid">
<div class="container__col">
<h2><?php echo get_field("heading_first"); ?></h2>
<div>
<?php echo get_field($first_img['url']); ?>
</div>
<!-- <p><?php var_dump($first_img['url'])?></p> -->
</div>
<div class="container container__col">
<p><?php echo get_field("content_first"); ?></p>
</div>
</div>
</div>
Advanced Custom Fields can be set to return data in a few ways. It looks by your code like this image field is set to return 'Array'. So the way you're grabbing it, $first_img is an array of your data, with URL being the source of the original, uncropped image. What you actually have isn't an 'image' itself - just the data.
On this line, you're trying to REFETCH the field data, with the URL which isn't correct:
<?php echo get_field($first_img['url']); ?>
Instead, what you're looking for is something like:
<img src="<?php echo $first_img['url']; ?>" alt="<?php echo $first_img['alt']; ?>"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.