I’m trying to add the width and height attributes to the wp_get_attachment_image_src. Why is this returning width and height:0?
<?php
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'two' );
if ($image) : ?>
<img class="attachment-two" src="<?php echo $image[0]; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" />
<?php endif; ?>
Thank you!
What is
'two'
referring to? Is that a custom image size?Place the following
var_dump('<pre>',$image,'</pre>');
after your declared$image
variable like so,and provide the results so we can inspect the output.
As per Codex the second argument in this function,
wp_get_attachment_image_src( $attachment_id, $size, $icon );
…refers to the specified size you want returned.
There fore
'two'
should refer to the name of the custom image size you added with,http://codex.wordpress.org/Function_Reference/add_image_size
Have you done that?
If yes, did the image exist prior to creating the custom image size or after creating the custom image size?
If the image existed before you created the custom image size then that image in question that you are trying to retrieve does not have the applied image size as a generated version of its original. You would need to regenerate thumbnails to have it apply thats the case.