Hide pdf preview

Hi, is it possible to hide PDF viewer ?

In FSE template with the Tainacan Item Media Gallery, instead of displaying the full PDF viewer, I just want to show the cover image (thumbnail) and a simple download link.

I can’t find information on that.

I’m afraid you won’t be able to do this without code… we should probably add some function for that in the future. Here is how you would to today. Add this to your themes function.php:

wp_embed_unregister_handler( 'pdf');

This will disable Tainacan’s autombed feature for PDFs. Actually what we do is render the file inside an Iframe and if the browser supports PDF file previews, it will use its native PDF reader:

Now all that will appear in the document section is a direct link to the PDF file. I you want to change that to something more appropriate such as customized download link you can actually register your own PDF embed handler as we did in that class an tweak the output.

1 curtida

OK i can code some little plugins so i will try some customization.

Thank you very much this is a good start for me.

I apologize if it’s not okay to jump in here, but I actually had a similar question…if I wanted to modify the embed, not get rid of it entirely, how would I do that? For instance, if I wanted to change the width and height of the viewer.

Do I add the code from class-tainacan-embed.php into my functions.php file? I’m working off of a customized child theme.

@joannep you could put the code in your child theme’s function.php. First, calling that line I mentioned would unregister Tainacan’s embed provider for PDF files. Then you register your own like this:

wp_embed_register_handler( 'pdf', '#^https?://.+?\.(pdf)$#i', 'my_pdf_embed_handler' );

In your my_pdf_embed_handler function code you could do the same that we do but instead put your desired dimensions.

Just keep in mind that the height and width of the element in the media gallery are not bound only by the iframe’s direct attributes… so it might be a work that leads to nothing. There are a series of wrappers around that element and each may be applying limits or constraints to how much it can grow. Even in your theme’s single page template there might be limits to how much the element can grow.

These things you would have to work around via CSS. For example, there is one class applied to the figure wrapper that forces the iframe perspective to be 4:3. To change it you would need something like:

.tainacan-embed-aspect-4-3.tainacan-content-embed.tainacan-has-aspect-ratio {
     max-width: calc(var(--tainacan-media-main-carousel-height, 60vh) * 4 / 3)  !important;
}

Play with the 4 and 3 there to see the results. And again to change something like the maximum height of the overall carousel you could do something like:

.tainacan-media-component {
  --tainacan-media-main-carousel-height: 90vh !important;
}