1

I have an ACF custom field for "File". It allows users to upload PDF files of some reports.

In the Media section in WP Admin, I can see that the PDF we upload auto-generates the thumbnails.

On the frontend, in my theme for the website, when I try to see the files array from the custom field, there's nothing related to the file that contains its thumbnail. Is there some way I can access the thumbnail for the PDF?

I know I can generate this myself using imagick or GD, but I'd like to leverage what WP has already done.

1 Answer 1

3

To get the attachment's icon, you can use wp_get_attachment_image().

For example, let's say I've uploaded a Word doc and it's got the ID 1234:

 // Parameter 3 - 'true' - tells WP to treat this as an icon.
 $img_tag = wp_get_attachment_image( 1234, 'thumbnail', true );
 // $img_tag contains:
 //   <img width="48" height="64"
 //        src="http://example.com/wp-includes/images/media/document.png"
 //        class="attachment-thumbnail size-thumbnail"
 //        alt="" loading="lazy"
 //   />
1
  • 1
    Thank you Pat. Super helpful!
    – Khom Nazid
    Apr 8, 2022 at 16:36

Your Answer

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

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