S
S
Sergey Burduzha2020-04-23 11:52:07
WordPress
Sergey Burduzha, 2020-04-23 11:52:07

Why is the wp_get_attachment_image_url function not cropping the image?

Good afternoon.
You need to insert a picture with the specified dimensions, but for some reason a large picture is always inserted.

<img src="<?php echo wp_get_attachment_image_url( get_post_thumbnail_id(), [ 330, 228 ] ); ?>" alt="">


5ea157237552e722332291.jpeg

Thanks in advance for the hint.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2020-04-23
@serii81

Read the documentation
https://wp-kama.ru/function/wp_get_attachment_image_url

The size of the image to get the URL for.
In this parameter, you can specify the basic WordPress sizes: thumbnail, medium, large or full.
Also, you can specify the size in an array, as two elements (width, height): array(32, 32). In this case, the most suitable size from the available ones will be selected, then the picture will be compressed / stretched to the specified sizes. Since version 2.5. this setting does not affect the size of media icons (icons for files), they are always shown in their original size.

Note that there is not a single word about cropping the image. It is said that the most appropriate image size will be selected.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question