How do I add a link to a PDF in the content, so that it downloads rather than opens in the browser windows? (I’ve uploaded the PDF to the media library and can insert the link but can’t find an option to prevent it opening in the browser window).
Thanks,
Lucy
you may try to add this to your .htaccess :
A PDF will be saved with mime-type of
application/pdf
, so if your theme has an application.php or pdf.php template file that forces download (or if you check for mime-type in your attachment.php template), you can force a download.A pdf.php file built like this in your theme should do the trick:
(Edit: I should note that in order for this to work, when you insert the file into your post through the media uploader, you have to select Post URL rather than File URL in the Link URL field before inserting into your post. A link to a filename will follow the browser’s preferences, but by linking to the WP post link, you can control its behaviour.)
Actually, that’s entirely dependent on the browser. Some browsers will open a PDF in the window using a built-in PDF reader (most use the Adobe plug-in, Google Chrome has its own). If the plug-in is missing, though, the browser will attempt to download the file instead.
Your safest bet is to add instructions on the page for the user to right-click and select “save as.”
If you’re concerned about users not being able to get back to the page after they click a link, add
target="_blank"
to the link and it will force the browser to open the link in a new tab or window. Sometimes, this can be enough to trigger a download instead as well.Eg:
<a href="http://site.url/document.pdf" target="_blank">Download PDF</a>
.Just use the a tag’s download attribute: https://www.w3schools.com/tags/att_a_download.asp