Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Need to pull thumb for ACF image. WordPress

  • SOLVED

I have an Advanced Custom Fields image field, and I pull the image with the following:

<img src="<?php the_field('home_image'); ?>">

I need to get the thumbnail of the image, and can't figure out how to simply do this.

If you know how, but it requires changing the image type in the ACF field to object, that's fine. I just need it to work.

Thanks!

Answers (1)

2015-03-27

timDesain Nanang answers:

Hi Sir,
You should chooce "Image ID" as The Return Value.
then use this code:

<?php
$att_id = get_field('home_image');
$img_array = wp_get_attachment_image_src( $att_id, 'thumbnail');
$img_url = $img_array[0];
?>
<img src="<?php echo $img_url; ?>">


Kyler Boudreau comments:

Tim - thanks. That didn't work. When I put that in that page, it breaks it. I copied exactly what you put in, and this isn't any weird theme. I'm using Underscores from Automatic, and just starting to build.

Any ideas? Thanks man!


Kyler Boudreau comments:

Further comment on that...the page breaking happens when I set the ACF image to ID, oddly enough. I always use URL, so haven't seen this before.


timDesain Nanang comments:

You need to resave the page once again to replace the value of the image field


Kyler Boudreau comments:

Oh okay. It's weird that it breaks the page though...I'll re-save now.


Kyler Boudreau comments:

Okay that worked. Another note: I'm using the ACF Image Crop plugin, and that was causing the page broken stuff when switching between URL and ID. Voting to you. Thanks!