This is very common thing to get an image on page or post. To get an image on template we can use pre-defined function from WordPress library.
wp_get_attachment_image( int $attachment_id, string|array $size = ‘thumbnail’, bool $icon = false, string|array $attr = ” )
Parameters #Parameters –
- $attachment_id –
(int) (Required) Image attachment ID. - $size –
(string|array) (Optional) Image size. Accepts any valid image size, or an array of width and height values in pixels (in that order). - Default value: ‘thumbnail’
- $icon –
(bool) (Optional) Whether the image should be treated as an icon. - Default value: false
$attr – string|array) (Optional) Attributes for the image markup.
Default value: ”
This function only gets an image that was uploaded to WordPress, it doesn’t output an image in the content of the post.