Support » Plugins » [Plugin: Advanced Custom Fields] Display custom image-size

  • Hi,

    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]; ?>" />
Viewing 5 replies - 1 through 5 (of 5 total)
  • 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.

    Thanks! Changing to Image ID was it for me.

    thanks onetrev, that works!

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

    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 );
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Plugin: Advanced Custom Fields] Display custom image-size’ is closed to new replies.