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.

1 Answer 1


The 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, [] );
  • Hi @JacobPeattie - when i do that it doesn't pull the image in. The image I'm using has a post ID of 142 so I've done wp_get_attachment_image( 142, 'large', false, [] ); but it doesn't work. Have I done that correctly?
    – pjk_ok
    Feb 26, 2020 at 13:15
  • Did you make sure to echo? And are you sure 142 is the is of the image, and not a post that it’s attached to? Feb 26, 2020 at 14:26
  • Oh boy. I was missing the echo. It's been a very long day. Thanks for you help Jacob.
    – pjk_ok
    Feb 26, 2020 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.