As said in this page, wp_get_attachment_image_src()only accepts built-in sizes such as thumbnail, medium, large or full.

How do you get the same return value with custom sizes you add with add_image_sizes() ?

1 Answer 1


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' ); 

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

  • thanks but that is not a proof, I'm already var_dump things to see it. Get nothing but the original thumbs. Guess the truth is elsewhere, I'm on wp beta 3.9 3, do not know if that matters
    – JMau
    Apr 6, 2014 at 17:26
  • Works when I try it and there is nothing in the source that I see that would limit the sizes. The problem you are having does not lie where you think it does, I am pretty sure. Tested on 3.9.
    – s_ha_dum
    Apr 6, 2014 at 17:35
  • I guess you're right I do not see that too. $size is a string.
    – JMau
    Apr 6, 2014 at 17:41
  • But it's weird it workw only with built-in sizes for me !
    – JMau
    Apr 6, 2014 at 18:18
  • 1
    Remember you need to regenerate all thumbnails in order for the new custom size to work. You can do this with code or with the plugin "Regenerate thumbnails".
    – Floris
    Sep 16, 2019 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.