Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Robin Sturgeon
Robin Sturgeon
3,186 Points

Advanced Custom Fields Image crop

I am trying to get my images to crop to a certain size. I have defined the size in my functions file, but when I call it no image shows up.

   /**
 * Add automatic image sizes
 */
if ( function_exists( 'add_image_size' ) ) { 
    add_image_size( 'photos', 228, 148, true ); //(cropped)
}
<?php

    $attachment_id = get_field('photo');
    $size = "photos"; 
    $image = wp_get_attachment_image_src( $attachment_id, $size );

?>

<img alt="<?php the_field( 'photo_description' ); ?>" src="<?php echo $image[0]; ?>" />

What am I missing?

2 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Hi, when you change $size = "thumbnail" does it work?

Robin Sturgeon
Robin Sturgeon
3,186 Points

No. It shows the image description but no image.