Serving PDFs

Uploading Documents (*.doc, *.xls, *.pdf) to WP and addding a link a direct link inside a post looks good. But as soon as I want to download a PDF it gets openend in a new tab (and would expose the URL from the WP backend)

I have tried to force direct download with the following statement (https://www.philowen.co/blog/force-a-file-to-download-when-link-is-clicked/):

<a href="https://wp-hei-integration.dossis.ch/wp-content/uploads/2020/08/PB-Integration-PLUS.pdf" download="myfile.pdf">Click to Download</a>

but Chrome/Firefox still try to open the link. Any ideas? Or is there an alternate approach to serve static files uploaded to WP?

Hi @phn

If you look here you’ll see that the download attribute only works for same origin URLs.

I don’t think there’s a way to do what you want. By linking to a file on another server you’re going to expose the URL of that server.

Maybe someone else in the community has an idea how to avoid this.

2 Likes