Reputation: 133
Hi i have a wordpress site and i am trying to display image using wp_get_attachment_image_src but it returns only array
Below what i have tried with myself
`$get_story_image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "size" );`
if ( $get_story_image_src ) : ?>
<img src="<?php echo $get_story_image_src ; ?>" alt="story_image" />
<?php endif; ?>
Upvotes: 1
Views: 1578
Reputation: 2147
Its correct wp_get_attachment_image_src always returns array .
if you want to display image using this function you need to pass array indexes in the image tag .
Try below code :
`$get_story_image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "size" );`
if ( $get_story_image_src ) : ?>
<img src="<?php echo $get_story_image_src[0]; width="<?php echo $get_story_image_src[1]; ?>" height="<?php echo $get_story_image_src[2]; ?>" ?>" alt="story_image" />
<?php endif; ?>
Also its good if you read all the parameters of the functions before you used
Refer this link - https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/
Upvotes: 1