Home Forums General Issues Image size: attachment display settings


Image size: attachment display settings

  • When using the image field type on an edit screen, the wordpress “size” select menu is not displayed — the one that’s usually displayed in the insert media window along with “alignment” and “link to”:

    wordpress image sizes

    I can understand why “alignment” and “link to” are not available, but it would be really handy to be able to select various image sizes. Is there a way to enable this feature?

  • Hi @dadra

    I do agree, however, the image field only saves the attachment ID and no other data.

    You may need to add another field to allow for a custom size selection, or use a WYSIWYG field to insert the image with such data.


  • Thanks Elliot. Maybe a feature for the future?

    Sure, a WYSIWYG field would work…though it’s a bit heavy-handed just to insert an image. You mention I might need to add another field to allow for custom size selection. Any chance you can steer me in the right direction for how to do that?

    Thanks as always for your amazing work and awesome support.

  • Hi @dadra

    You could create a select field and populate the choices with ‘thumbnail, medium, large, full, custom-size, etc’.

    Then in your code, you can load in the image like so:

    $image = get_field('image');
    $size = get_field('size');
    echo $image['sizes'][ $size ];

    The above example expects your image field to return an array of data, but you could change this to ID and modify the code as per the docs.


  • Excellent, thanks a ton!

  • I was looking for the same thing and tried the example above, was the good way but no so simple for me, finally it done this :
    1 : create the checkbox field with the different size
    (thumbnail : thumbnail
    medium : medium
    large : large
    full : full
    custom-size : custom-size)
    2 : the code to display

    $attachment_id = get_field('image');
    $field = get_field_object('size');
    $value = get_field('size');
    $label = $field['choices'][ $value ];
    $image = wp_get_attachment_image_src( $attachment_id, $label );
    // url = $image[0];
    // width = $image[1];
    // height = $image[2];
    <a href="<?php echo $image[0]; ?>" class="fancybox"><img src="<?php echo $image[0]; ?>" /></a>

    It works good and the check box very easy to use !
    Now have to find a solution to the Gallery field…

    We really need this feature, without all the pictures are full size !! it looks a detail but when you have a lot of pictures to manage you understand how important it is. Many Thanks ! ACF is great !

  • Still searching to do this with the gallery field add on… cannot make something work. Will be easier I guess with a repeater field.
    The difficulty I think is how to get the attachement id for each image as the gallery field call for all pictures $attachment_id = get_field('gallery');' not working. So I tried this:

    *  Gallery
    // url = $image[0];
    $images = get_field('gallery');
    $field = get_field_object('size-gallery');
    $value = get_field('size-gallery');
    $label = $field['choices'][ $value ];
    if( $images ): ?>
                    <?php foreach( $images as $image ): ?>
    				<?php $image2 = wp_get_attachment_image_src( $image['id'], $label ); ?>
    			<a href="<?php echo $image2[0]; ?>" class="fancybox" rel="gallery" title=""><div class="miniature"><img src="<?php echo $image2[0]; ?>" /></div></a>
    	            <?php endforeach; ?>
    <?php endif; ?><!--FIN DE GALERIE PHOTOS -->

    The gallery works but the $label has no effect.

    Any idea would be great. I really need to make it works. Thanks

  • Hi @wpforaine

    Have you debugged your code line by line?

    I notice that you are finding the selected size like so:

    $field = get_field_object('size-gallery');
    $value = get_field('size-gallery');
    $label = $field['choices'][ $value ];

    But this would be better written like so:
    $label = get_field('size-gallery')

    Please debug. It’s the only way to check your variable data and find out why code isn’t working.


  • Hi Elliot, I’ve just seen your answer so I haven’t tried what you said yet. But it’s weird cause now it’s working, I just changed the check box to a select box… Maybe because with the select I only allowed one choice. I don’t really know/anderstand, but whatever I will change my code as you said to have a cleaner code.
    Thank you.

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

The topic ‘Image size: attachment display settings’ is closed to new replies.