How to dynamically display image from which the thumbnail is generated by Wordpress?

Hello.

When adding images to the library - it is cut to a certain size using the plugin (tinypng) and overwrites the original. From this picture it turns out a thumbnail with smaller size.

Question: how do I output the original image (which yields miniature) dynamically (not by ID)? Or how to get the ID of the images for further work automatically?

The picture you want to display on post page without using the editor.

I think we need to use <?php echo wp_get_attachment_image( ); ?>, but then is captured only miniature.

To make it even clearer: the effect should be exactly the same as if I put a picture from the media library in the editor post.
June 7th 19 at 14:29
1 answer
June 7th 19 at 14:31
Solution
Hello.

In the case of the function wp_get_attachment_image, You can specify the size of the second parameter. The original is full.
$img = wp_get_attachment_image( $attachment_id, 'full' );

If this image posts or pages, you can use the functions the_post_thubmnail or the_post_thumbnail_url.
<?php the_post_thumbnail('full'); ?>

<img src="<?php the_post_thumbnail_url('full'); ?>" alt>
The thumbnail is normally displayed. But I need a picture of a miniature. Also the larger image. Can't figure out how to get him. - Lacey.Torphy14 commented on June 7th 19 at 14:34
,
The thumbnail is normally displayed.

What is a thumbnail and what You get?

But I need a picture, which turns out miniature. Also the larger image.

Indicate "full" — you get the picture from where you generate the thumbnail. In the response there are examples of code. - alexandrea_Vandervo commented on June 7th 19 at 14:37
Thank you! Here it worked:
<img src="<?php the_post_thumbnail_url('full'); ?>" alt>
- Lacey.Torphy14 commented on June 7th 19 at 14:40

Find more questions by tags WordPressImagesMiniatures