Home Forums General Issues Display thumbnail in post


Display thumbnail in post

  • Hello,
    I’d like to display large thumbnail in post. I have following code:

    		$image = get_field('photo_1');
    		$size = 'large'; // (thumbnail, medium, large, full or custom size)
    		if( $image ) {
    		echo wp_get_attachment_image( $image, $size );

    But it doesn’t work as I’d like.
    I have my large thumbnail width set to 1220px
    And html is:
    <img width="640" height="427" src="...-1220x814.jpg" class="attachment-large" alt="...">
    So it gets good image but I don’t know where from is width=”640″…

    Any idea where can be the problem?

  • Hi @marek-234

    Hmm.. what return value have you set for the image field?
    You could just set it to return an image object then do this:

    <?php $image = get_field('photo_1'); ?>
    <img src="<?php echo $image['sizes']['large']; ?>" width="<?php echo $image['sizes']['large-width']; ?>" height="<?php echo $image['sizes']['large-height']; ?>" alt="<?php echo $image['alt']; ?>" />
  • Hi Jonathan,
    Thanks for the answer.
    In Return Value I have set Image Object.
    With your code I get the same:

    <img src="...-1220x814.jpg" width="640" height="427" alt="">

    So again good image but that width=”640″…

  • That’s seriously wierd.. I think it’s got more to do with how WP has created the image than ACF.. it’s probably something gone wrong when uploading the images or something.

    But in any case.. you do not need to add the width and height parameters of an img element. It’s perfectly fine leaving them out!
    So just go ahead and remove those and you’ll be fine!

  • Thanks, Jonathan. Yes I don’t need width and height as I have responsive design. But I thought you’d like to know the issue but maybe that’s really wp not acf problem.

  • Yeah I think it’s WP not behaving as ACF loads up those values from WP functions.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Display thumbnail in post’ is closed to new replies.