Ready to get started?Download WordPress


[Plugin: Advanced Custom Fields] Display custom image-size (6 posts)

  1. freshes
    Posted 1 year ago #


    I have some issues with Advanced Custom Fields plugin. The custom field image uses the dimensions of my predefined thumbnail-size, but I want it to use the medium-size. I tried some of the advises from the support-board and put the code into my template file (see below), but it doesn't have any effect no matter what I'm trying. Help is much appreciated.

    $attachment_id = get_field('field_name');
    $size = "medium"; // (thumbnail, medium, large, full or custom size)
    $image = wp_get_attachment_image_src( $attachment_id, $size );
    // url = $image[0];
    // width = $image[1];
    // height = $image[2];
    <img src="<?php echo $image[0]; ?>" />
  2. onetrev
    Posted 1 year ago #

    That should do it...but one key thing is when setting up the field make sure to select the "Return Value" as Image ID, not Image URL like you would if you were just using a the_field() function. I always forget to do that, but just change it to that and it should work for you.

  3. leopoldkristjansson
    Posted 8 months ago #

    Thanks! Changing to Image ID was it for me.

  4. joga3001
    Posted 3 months ago #

    thanks onetrev, that works!

  5. vmatt21
    Posted 3 months ago #

    Sorry, I'm still confused. Could you post the corrected code here?
    Thanks - you guys are awesome!

  6. onetrev
    Posted 3 months ago #

    The code above, in the original post is correct, you just have to make sure the return value for the field is IMAGE ID, as I mentioned. If it helps this is another way you can write the code:

    <?php $attachment_id = get_field('field_name'); // NOTE: make sure image field returns Image ID -- not URL!!!!!
    	$size = "full"; // (thumbnail, medium, large, full or custom size -- as set in functions.php)
    	echo wp_get_attachment_image( $attachment_id, $size );

Topic Closed

This topic has been closed to new replies.

About this Topic