wp_get_attachment_image_src() and custom sizes

You are misreading the Codex. wp_get_attachment_image_src() works just fine with custom image sizes.

Proof of concept:

// copied from the Codex
// https://codex.wordpress.org/Function_Reference/add_image_size
if ( function_exists( 'add_image_size' ) ) { 
    add_image_size( 'category-thumb', 300, 9999 ); //300 pixels wide (and unlimited height)
    add_image_size( 'homepage-thumb', 220, 180, true ); //(cropped)
}

Add an image to the Library, then…

$image_attributes = wp_get_attachment_image_src( 28, 'category-thumb' ); 
var_dump($image_attributes);

You will notice that the image returned is (an appromixation of) 300×9999– that is 300 wide by whatever height scales correctly.

Leave a Comment