A
A
arhis772022-03-15 16:20:32
Images
arhis77, 2022-03-15 16:20:32

Wordpress - get image size?

Friends, such a question, Google PageSpeed ​​swears that the images are not set accordingly. sizes, tell me, how can I display the size of the picture in the template if it is different on each page. Those. you need to somehow get the size of the image in order to later display it in the img tag.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2022-03-20
@artzolin

When using the image request functions, almost everyone has a $size parameter that you can pass in the size you want.

$img = wp_get_attachment_image( $attachment_id, $size, $icon, $attr );

Better yet, use the properties of the <img> srcset tag , where you can pass references to all available image sizes. Of these, the browser will be able to choose the most appropriate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question