• Hello,

    I uploaded a PDF file to the web and created a link to it.

    The problem is that the browser displays it. It’s not really bad, with an open file you can even download it. However, the contents of the file are embedded on the page. The PDF is only there if someone wants to download it.

    Therefore, it is completely unnecessary for the link to do anything other than download the PDF file.

    However, I cannot create such a link. I found that it could be done with the download attribute, but it didn’t help at all.

    Please help

    Thank you

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi, if you are in the block editor, there may be another approach you can try to get the download to work. Once you’ve added your PDF if you toggle ‘Show inline embed’ to off the download will work directly from the link.
    Take a look: https://cldup.com/5tvgsp0BYV.png

    If you are doing this a different way, it could be helpful to share more information like a screenshot, to help further troubleshoot.

    Thread Starter michalrama

    (@michalrama)

    Hello,

    I inserted a paragraph where I changed part of the text to a link.

    Yes, when I insert a PDF file there, it is possible to disable its display (see your image), there is also the option to add a download button there.

    However, the point is that when I click on a link, the PDF is displayed (not downloaded). But, each browser approaches it differently.

    Could it be solved using PHP? That I would insert a link there that only calls PHP code that only downloads the file?

    Thread Starter michalrama

    (@michalrama)

    Hello,

    Yes thank you. This is exactly what I need.

    But I don’t know exactly how to call such code in wordpress?

    I mean how to create a PHP function and call it with the help of a button? This is probably done via the onclick attribute, but how do I define it when I have it written, for example, using the PHP code snippet plugin? Thank you

    Do you know that, please?

    hi @michalrama using the download link feature in the file editor would be the optimal approach if using the block editor.
    There might be something else happening concurrently, so if you could it would help us troubleshoot if you could send a screencast or video of what is happening so we can dig in further.

    If you switch to Code view (or use Edit as HTML) for a text link, you could add the download attribute (either on its own or with a different file name):
    <a href="/wp-content/uploads/sample.pdf" download>Download sample PDF</a>
    <a href="/wp-content/uploads/sample.pdf" download="file-name">Download sample PDF as "file-name.pdf"</a>

    If you want to it to look more like a button than a text link, you could try this in the File block:
    1. Uncheck the “Show inline embed” toggle.
    2. Toggle on the Download button option (if it is not already on).
    3. Edit the text for the “Download” link to include the file name (or other identifying text).
    4. Delete the file name text link so it shows the “Write file name…” placeholder. (When the file name link’s text is empty, the link is not created.)

    Thread Starter michalrama

    (@michalrama)

    Hello @sabernhardt

    I’ve tried all this before. And the problem is that every browser treats it differently.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Is it possible to create a link that only downloads a PDF file?’ is closed to new replies.