When I found a couple of years ago that WordPress will create thumbnails of uploaded PDFs, I was so happy, thinking I wouldn't have to make and upload separate PDF cover images to have a thumbnail display on my site as the link to a PDF. After some struggle I found that the images created from the uploaded PDFs aren't accessible for display on any public webpage. It seems logical to me that since these files are created when I upload a PDF, I should be able to access them, but this isn't possible. I want to clarify that I don't what to embed the PDF (some are very large), I just want the automatically-generated thumbnail to the be the link to the PDF.
I tried the plugin PDF Thumbnails, but it's clunky at best and it doesn't use the automatically-generated images; it has to create its own.
This seems like such a simple and obvious thing to do so I'm really surprised that this isn't possible "out-of-the-box". If I see the thumbnail in admin, why can't I see it on the live site, too?
The post Force documents to appear in Featured Image dialogue doesn't help me because the Twenty Twenty-three theme doesn't have the typical functions.php file and post-type template files, at least that I can find. I should also note that I am using multisite.
Thanks.
When I found a couple of years ago that WordPress will create thumbnails of uploaded PDFs, I was so happy, thinking I wouldn't have to make and upload separate PDF cover images to have a thumbnail display on my site as the link to a PDF. After some struggle I found that the images created from the uploaded PDFs aren't accessible for display on any public webpage. It seems logical to me that since these files are created when I upload a PDF, I should be able to access them, but this isn't possible. I want to clarify that I don't what to embed the PDF (some are very large), I just want the automatically-generated thumbnail to the be the link to the PDF.
I tried the plugin PDF Thumbnails, but it's clunky at best and it doesn't use the automatically-generated images; it has to create its own.
This seems like such a simple and obvious thing to do so I'm really surprised that this isn't possible "out-of-the-box". If I see the thumbnail in admin, why can't I see it on the live site, too?
The post Force documents to appear in Featured Image dialogue doesn't help me because the Twenty Twenty-three theme doesn't have the typical functions.php file and post-type template files, at least that I can find. I should also note that I am using multisite.
Thanks.
The PDF images created by wordpress are stored within the PDF attachment object metadata.
[
{
"id": 121,
"media_type": "file",
"mime_type": "application/pdf",
...
"media_details": {
"sizes": {
"full": {
...
"source_url": "<domain>/wp-content/uploads/document-name-pdf.jpg"
}
}
]
Adding an image block or adding a featured image to a post requires an attachment ID
and not simply a url probably
An attachment ID
can be created by "side loadeding" the url
into the media library to create an attachement using the media_sideload_image
function which can return the newly created attachment ID
media_sideload_image
function$pdf_image_url = $PDF_object -> media_details -> sizes -> full -> source_url;
$attachment_id = media_sideload_image(
$pdf_image_url,
$post_id, // the post to attach the image
'My image title',
$return_type = 'id'
);
$image = set_post_thumbnail( $post_id, $attachment_id );
The function set_post_thumbnail( $post_id, $attachment_id )
can be used to assign an image to a post as the featured image
media_details
- example$value -> media_details -> sizes -> full -> source_url
– dj.cowan Commented Mar 16, 2024 at 0:21