L
L
Legal Adviser2020-04-14 18:24:19
WordPress
Legal Adviser, 2020-04-14 18:24:19

Why does this happen with pictures?

Hello everyone,
I noticed something incomprehensible to me and I can’t understand where my legs grow from ...
Situation:
If we display a picture for recording through:
the_post_thumbnail(array(200,100))
Then the code for some reason is like this:

<img width="178" height="100" src="http://localhost:8089/wp-content/uploads/2020/02/robot-wallpaper-17.jpg" class="attachment-200x100 size-200x100 wp-post-image" alt="робот" srcset="http://localhost:8089/wp-content/uploads/2020/02/robot-wallpaper-17.jpg 1920w, http://localhost:8089/wp-content/uploads/2020/02/robot-wallpaper-17-300x169.jpg 300w, http://localhost:8089/wp-content/uploads/2020/02/robot-wallpaper-17-1024x576.jpg 1024w, http://localhost:8089/wp-content/uploads/2020/02/robot-wallpaper-17-768x432.jpg 768w, http://localhost:8089/wp-content/uploads/2020/02/robot-wallpaper-17-1536x864.jpg 1536w, http://localhost:8089/wp-content/uploads/2020/02/robot-wallpaper-17-1200x675.jpg 1200w" sizes="(max-width: 178px) 85vw, 178px">

And if the output is:
the_post_thumbnail(array(100,100))
Then the code is:
<img width="100" height="100" src="http://localhost:8089/wp-content/uploads/2020/02/robot-wallpaper-17-150x150.jpg" class="attachment-100x100 size-100x100 wp-post-image" alt="робот">


Who will prompt where to dig? And why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2020-04-15
@azerphoenix

I can assume the following ...
the_post_thumbnail(array(100,100))
such a proportion of the picture (1: 1) is available. Thumbnail - thumbnail size 150x150.

src="http://localhost:8089/wp-content/uploads/2020/02/robot-wallpaper-17-150x150.jpg"

But, such a proportion of the picture (2:1)
the_post_thumbnail(array(200,100))
is not available and, accordingly, there is nothing to output to the VP ... This
is why it turns out the following:
width="178" height="100" src="http://localhost:8089/wp-content/uploads/2020/02/robot-wallpaper-17.jpg"

It displays the full size of the image and limits it with styles...
To solve the problem:
1)
add_image_size( 'customThumbnail', 200, 100, true );
in functions.php
https://wp-kama.ru/function/add_image_size
2) Install regenerate thumbnails and run all your pictures. Then a new thumbnail size of 200x100 pixels will be created. and VP uses them. Or later you can explicitly specify the desired thumbnail in the_post_thumbnail. the_post_thumbnail('customThumbnail')
https://wp-kama.ru/function/the_post_thumbnail

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question