Support

Account

Home Forums Add-ons Repeater Field Custom Image Size without Cropping Reply To: Custom Image Size without Cropping

  • homepage-thumb is the name I came up with, you can call it anything you like. So for instance, you could set up your functions.php file like this:

    if ( function_exists( 'add_image_size' ) ) {
    	add_image_size( 'my-custom-thumb-name', 97, 83, true );
    }
    
    add_filter( 'image_size_names_choose', 'my_custom_sizes' );
    
    function my_custom_sizes( $sizes ) {
        return array_merge( $sizes, array(
            'my-custom-thumb-name' => __('My Custom Thumbnail'),
        ) );
    }

    my-custom-thumb-name is the name of your additional image size (you can call it whatever you want).

    I would recommend not using the term “image” for anything just to make sure it doesn’t cause any conflicts (say with WP or with another plugin.)

    Then in your template, you could use this:

    <?php
    	$attachment_id = get_sub_field('my-image-subfield-name');
    	$size = "my-custom-thumb-name";
    	$image = wp_get_attachment_image_src( $attachment_id, $size );
    ?>
    
    <td class="feature-game-img"><img src= "<?php echo $image[0]; ?>" /></td>

    my-image-subfield-name is the the name of your subfield (again, I would avoid using “image” just in case).

    Then all you need to do is echo the image there. You’ll notice the attachment_id uses get_sub_field instead of just get_field.

    Theoretically this should work, although I haven’t tested it.

    Also you might not see an image if you don’t upload new images because WP would need to create the new image size you created during the upload to the media library.

    See if that works, and if not, let me know.