I see different topics on forcing a PDF to download but none of the solutions work for me.
Here’s my problem:
I am using ACF Pro to capture a list of files within a WP page. Then I’m using Loopers to display the name of the documents, as well as link to the document using a button. However, I’d like to force download the PDF instead of it opening in the browser.
Here’s what I’ve tried:
- Use JS code, and put the button in the class “forcedownload”
jQuery( document ).ready(function($) {
$( “.forcedownload” ).attr( “download”, “” );
}); - Use Custom Attributes to create an attribute “download” with value as the URL, in addition to the button’s URL parameter as the URL.
- #2, but with empty and placeholder values for attribute.
- #2, but with the URL field in Cornerstone as a placeholder or other random text
So far, the best result is #4, where I put “#” as the value in the URL parameter, and provide the actual URL to the attribute.
However, this downloads an empty PDF where special characters become “_”
For instance, https://something.com/media/files/something.pdf" as the URL downloads an empty file named “https___something.com_media_files_something.pdf” which obviously never existed.
Any suggestions on how to get this working?
BONUS: if I can hide the source URL from the user, even better!