Home › Forums › General Issues › ACF File – Preview of document
I’m unsure how to do this, but I’m trying to get a preview of a document, PDF or image. So instead of that placeholder image below, I’d like to to show the same size preview.
There isn’t any way to change the icon shown by ACF.
There are 2 hooks that might be used to alter what is displayed.
The first is acf/prepare_field https://www.advancedcustomfields.com/resources/acfprepare_field/. There isn’t much documentation on this one, but I don’t think it will let you do what you want to do. You’d need to figure that out.
The other hook is acf/render_field https://www.advancedcustomfields.com/resources/acf-render_field/. This hook also will not do what you want but it would let you add html to the field to show additional information, like a thumbnail of an image. I can’t say if you can show a PDF or other file type. You can see an example of using acf/render_field used to show and image for a URL field here https://github.com/Hube2/acf-filters-and-functions/blob/master/render-image-in-editor.php
Hello,
I had same issue and make this hook for it:
function acf_change_icon_on_files ( $icon, $mime, $attachment_id ){ // Display thumbnail instead of document.png
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) === false && $mime === 'application/pdf' ){
$get_image = wp_get_attachment_image_src ( $attachment_id, 'thumbnail' );
if ( $get_image ) {
$icon = $get_image[0];
}
}
return $icon;
}
add_filter( 'wp_mime_type_icon', 'acf_change_icon_on_files', 10, 3 );
Old one but here’s a quick way to do this:
add_filter( 'acf/load_attachment', 'custom_load_attachment', 10, 3);
function custom_load_attachment ($response, $attachment, $meta){
if ($response['type'] == 'image'){
$response['icon'] = $response['sizes']['thumbnail'];
}
return $response;
}
The topic ‘ACF File – Preview of document’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.