Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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() ?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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) 300x9999-- that is 300 wide by whatever height scales correctly.

share|improve this answer
    
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 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 at 17:35
    
I guess you're right I do not see that too. $size is a string. –  JMau Apr 6 at 17:41
    
But it's weird it workw only with built-in sizes for me ! –  JMau Apr 6 at 18:18
    
There is something else wrong. Try with a bundled theme and no plugins. –  s_ha_dum Apr 6 at 18:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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