A
A
Andrey Filimonov2017-04-15 22:24:16
PHP
Andrey Filimonov, 2017-04-15 22:24:16

How to deal with displaying image thumbnails in WordPress?

Hello, please explain how to use automatically generated image thumbnails.
There is a code that displays a preview of the post, it contains the line

<div class="size-img"><?php the_post_thumbnail(array()); ?></div>
as I understand it from here, this code displays a thumbnail of the picture, but if you put medium instead of thumbnail, it gives an error. Why?
If you copy the link to the image on the blog page itself, then it is copied without the -150x150 addition. Does this mean that the full version is displayed?
If you look at the html code, it gives this:
<div class="size-img"><img width="900" height="876" src="http://vh166963.eurodir.ru/wp-content/uploads/polza_stretchinga.jpg" class="attachment- size- wp-post-image" alt="польза от растяжки" srcset="http://vh166963.eurodir.ru/wp-content/uploads/polza_stretchinga.jpg 900w, http://vh166963.eurodir.ru/wp-content/uploads/polza_stretchinga-300x292.jpg 300w, http://vh166963.eurodir.ru/wp-content/uploads/polza_stretchinga-768x748.jpg 768w" sizes="(max-width: 900px) 100vw, 900px" /></div>
Does this mean all images are uploading? And where is the option -150x150?
If you put zeros for all sizes in Settings-->Media files, cf928525310b4393bc260df9226a954a.png
then all the same, images (duplicates) 768x some pixels are created in the uploads folder. Why? How to avoid?
How to organize it correctly so that one original is loaded and only a thumbnail, for example, 300 px, is displayed in the preview of the article?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2017-04-15
@fil_and

If you put zeros for all sizes in Settings-->Media files, then all the same, images (duplicates) 768x some pixels are created in the uploads folder. Why? How to avoid?

Go to the page of your site, /wp-admin/options.phpfind the field medium_large_size_win it, apparently you have 768 - and put 0.
Why put 0 everywhere? - So that no pictures from the original are created
Yes, original uploaded by you
No, only 1 of all is loaded, which is optimal for the resolution of the device from which the site is opened.
Read about src and srcset
Put on the page /wp-admin/options-media.phpat the thumbnail: width 300
Display a thumbnail in the template simply:
<div class="size-img">
  <?php the_post_thumbnail(); ?>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question