Support

Account

Home Forums Front-end Issues Displaying File Thumbnail

Solving

Displaying File Thumbnail

  • I have searched high and low for an answer to this and can’t seem to find anything. I am trying to display a thumbnail for a File field and can’t get it to work. I have used the snippet from the documentation and all I get:

    <a href="http://www.3badge.com/trade18/wp-content/uploads/sites/27/2018/02/BZ_ST4up_EBM.pdf" title="BZ_ST4up_EBM">
    <img src="">
    <span>BZ_ST4up_EBM</span></a>

    Can someone please help?
    Thanks in advance!

  • You can use wp_get_attachment_image() https://developer.wordpress.org/reference/functions/wp_get_attachment_image/, wp_get_attachment_image_src() https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/ will also work.

  • Thanks for your response! Does this work for PFDs as well?

  • Yes, it does. If you set $icon to false it will return the thumbnail that was generated when the pdf was uploaded. For any file type that does not have thumbnails you need to set $icon to true and then you’ll get whatever icon WP thinks is best… this is hit or miss. The WP icons are not very good.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Displaying File Thumbnail’ is closed to new replies.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.