How to create a link that calls PHP code?
-
Hello,
How do I create a link in WP that redirects me to no page or file, but calls PHP code, please?
Thank you
-
This topic was modified 4 years, 8 months ago by
Jan Dembowski.
-
This topic was modified 4 years, 8 months ago by
-
This doesn’t really make sense.
Describe what you are trying to acheive.This doesn’t really make sense.
Describe what you are trying to acheiveI want the link to the pdf file to do nothing more than download it. The problem is that the pdf file can be read by the browser and everyone accesses the link differently.
That’s why I thought of solving it with PHP. I mean create PHP code to download the file. But I don’t know how to create a link in wp that executes PHP code?
Again – you’re not describing what you are trying to accomplish for the frontend user.
What is the problem are you trying to solve?> The problem is that the pdf file can be read by the browser
> and everyone accesses the link differently.Okay – and what’s wrong with that?
Again – you’re not describing what you are trying to accomplish for the frontend user.
What is the problem are you trying to solve?The point is that the contents of the pdf file I embedded in the page. And I wanted to add the option to download the PDF itself.
Okay – and what’s wrong with that?
The problem is that the browser tends to open this, which is unnecessary because its content is embedded on the page.
And I can’t solve this problem. So I thought of using PHP. The link won’t point to the file, but will only call the PHP code that will download the file.
It might work in any browser. But I don’t know how to create such a link in wp.
I found some nice code that might solve my problem not downloading the PDF. However, I don’t know where to write it. wp-config.php?
Peronsally, I don’t think you should be forcing things like this on the user, and sometimes you may run into issues with the browser settings or AV settings of the user.
You can try to force a download using the download attribute in your href:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attributes
https://developers.google.com/web/updates/2011/08/Downloading-resources-in-HTML5-a-downloador, you could update your .htaccess file like this:
https://gist.github.com/simplistik/2001897> I found some nice code that might solve my problem
It depends.
You would need to share the code on here.It depends.
You would need to share the code on here.Sorry, a mistake has crept in.
https://stackoverflow.com/questions/20080341/correct-php-headers-for-pdf-file-download
You can try to force a download using the download attribute in your href:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attributes
https://developers.google.com/web/updates/2011/08/Downloading-resources-in-HTML5-a-downloadI’ve tried that before, but every browser approaches it differently, so unfortunately this isn’t a universal solution.
Hello @corrinarusso,
Sorry for the late reply. I mean write a PHP function and call it with the help of a button? This is probably done via the
onclickattribute, but how do I define it when I have it written, for example, using the PHP code snippet plugin? Thank you
The topic ‘How to create a link that calls PHP code?’ is closed to new replies.