Gets the <img> tag of the image of the specified attachment (file attached to the post).
If the attachment cannot be found, an empty string will be returned.
If the attachment is an image, the code corresponding to the specified size will be returned (see the $size parameter).
For attached files of types other than images (.zip, .xls, .flv), an icon corresponding to that type will be returned (automatically determined by WordPress). By default, such an icon is not displayed; to display it, the 3rd parameter ($icon) must be set to true.
ID of the attachment whose image needs to be retrieved.
$size(string/array)
Image size. Can be specified as:
A string thumbnail, medium, large, full or the name of an existing size
An array of 2 elements defining the dimensions of the displayed image: array(32,32).
Specifying dimensions via an array does not physically reduce the image; it is only visually reduced from the most suitable prepared thumbnail (uploads).
Specifying dimensions does not affect the sizes of displayed icons for files; they are always displayed in their original size (32x32).
Instead of using an array, it is often better to register a new size using add_image_size() and use it alongside the already established (thumbnail, medium, large, or full). This approach is more efficient, as there is no need to constantly search for the appropriate size that will then be reduced by the browser.
Default: "thumbnail"
$icon(boolean)
Whether to use media icons to represent the attachment. By default, for file-type attachments (not images), the icon will not be displayed; if you need to display icons for such types of attachments, set this parameter to true. Default: false
$attr(array)
Any attributes for the <img> tag in an array. For example:
<img width="250" height="250"
src="http://example.com/image-250x250.png"
class="attachment-medium size-medium"
alt="Text from Alt Text field"
/>
alt text will be filled in only if it is specified for the attachment in the special field (alt text). The alt does not include the text from the title, description or caption of the image.
Display a picture of the specified size 20x20 pixels, for attachments of the "image" type, and the corresponding icon for other attachment types (the 3rd parameter):
$attach_id - can be taken as get_post_thumbnail_id() or $post->ID if you use the loop of images. You can create such a loop by using function get_posts() (get_posts('post_type=attachment')).
0
#3 Specify class, alt and title attributes for the picture