I currently have a custom theme with some images in a separate image folder and I pull them into the frontend with the echo get_theme_file_uri('/img/image-name.jpg')
which works as expected.
I would like to be able to add images from the media library, I know I can do this with the_post_thumbnail()
, but this obviously pulls in the post thumbnail relating to a post, whereas I've designed a page that uses 4 different images.
Is there a template tag that pulls in an image out of the media library onto a page where I can use the image's ID, so you get the benefits the_post_thumbnail()
brings in terms of sizing images etc ?
Any help would be amazing.
I currently have a custom theme with some images in a separate image folder and I pull them into the frontend with the echo get_theme_file_uri('/img/image-name.jpg')
which works as expected.
I would like to be able to add images from the media library, I know I can do this with the_post_thumbnail()
, but this obviously pulls in the post thumbnail relating to a post, whereas I've designed a page that uses 4 different images.
Is there a template tag that pulls in an image out of the media library onto a page where I can use the image's ID, so you get the benefits the_post_thumbnail()
brings in terms of sizing images etc ?
Any help would be amazing.
Share Improve this question edited Feb 26, 2020 at 14:41 pjk_ok asked Feb 25, 2020 at 23:58 pjk_okpjk_ok 9082 gold badges15 silver badges36 bronze badges1 Answer
Reset to default 2The equivalent function for arbitrary images that aren't the post thumbnail is wp_get_attachment_image()
. It works similarly, but you need to pass the attachment ID, and there's an $icon
argument that doesn't really do much:
echo wp_get_attachment_image( $attachment_id, 'large', false, [] );