0

Is there any way to retrieve the current post's generated featured image size, width and height.

For example if any post's featured image set is of size 540 x 400, although it should be of 550 px x 550 px (according to the thumbnail size registered, but it was not able to generate it due low size).

How to retrieve the current post's featured image size to store $width = 540 & $height = 400 in the current example.

Please help me to find a way!
Any help will be appreciated!

1 Answer 1

2

Have a look to wp_get_attachment_image_src(), which gives precisely data you need (URL and dimensions). Which help to figure out your problem.

sample code

$image_attributes = wp_get_attachment_image_src( $attachment_id = 10 ); if ( $image_attributes ) : ?> <img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>" /> <?php endif; ?> 

The return section gives keys, but the function just returns indexes as.

array{ [0] => url, [1] => width, [2] => height, [3] => is_intermediate (boolean) } 

We should make it clearer what is returned by this function. And some description or a link to explain is_intermediate.

1
  • Can you please show me the way to do it, i am confused. It will help a lot thank you! Commented May 7, 2018 at 7:38

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.