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!

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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