How to get cropped thumbnail source for custom post type

You should add your custom image size with this code:

add_image_size( 'my-test-image-size', 148, 148, true );

Then in your template file you can get cropped image using wp_get_attachment_image_src like this:

$attachment_id = ...;  // i.e. get_post_thumbnail_id()
$image_info = wp_get_attachment_image_src($attachment_id, 'my-test-image-size');
echo '<img src="'. $image_info[0] .'" ... />';  // $image_info[0] contains url of cropped image

To be more precise… wp_get_attachment_image_src returns an array containing:

  • [0] => url
  • [1] => width
  • [2] => height
  • [3] => boolean: true if $url is a resized image, false if it is the original.