Title: How to create a link that calls PHP code?
Last modified: September 16, 2021

---

# How to create a link that calls PHP code?

 *  [michalrama](https://wordpress.org/support/users/michalrama/)
 * (@michalrama)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/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, 9 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).

Viewing 10 replies - 1 through 10 (of 10 total)

 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/how-to-create-a-link-that-calls-php-code/#post-14876335)
 * This doesn’t really make sense.
    Describe what you are trying to acheive.
 *  Thread Starter [michalrama](https://wordpress.org/support/users/michalrama/)
 * (@michalrama)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/how-to-create-a-link-that-calls-php-code/#post-14877647)
 * > This doesn’t really make sense.
   >  Describe what you are trying to acheive
 * I 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?
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/how-to-create-a-link-that-calls-php-code/#post-14878397)
 * 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?
 *  Thread Starter [michalrama](https://wordpress.org/support/users/michalrama/)
 * (@michalrama)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/how-to-create-a-link-that-calls-php-code/#post-14878962)
 * > 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.
 *  Thread Starter [michalrama](https://wordpress.org/support/users/michalrama/)
 * (@michalrama)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/how-to-create-a-link-that-calls-php-code/#post-14879013)
 * 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?
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/how-to-create-a-link-that-calls-php-code/#post-14879017)
 * 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://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attributes)
   [https://developers.google.com/web/updates/2011/08/Downloading-resources-in-HTML5-a-download](https://developers.google.com/web/updates/2011/08/Downloading-resources-in-HTML5-a-download)
 * or, you could update your .htaccess file like this:
    [https://gist.github.com/simplistik/2001897](https://gist.github.com/simplistik/2001897)
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/how-to-create-a-link-that-calls-php-code/#post-14879020)
 * > I found some nice code that might solve my problem
 * It depends.
    You would need to share the code on here.
 *  Thread Starter [michalrama](https://wordpress.org/support/users/michalrama/)
 * (@michalrama)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/how-to-create-a-link-that-calls-php-code/#post-14879163)
 * > 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](https://stackoverflow.com/questions/20080341/correct-php-headers-for-pdf-file-download)
 *  Thread Starter [michalrama](https://wordpress.org/support/users/michalrama/)
 * (@michalrama)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/how-to-create-a-link-that-calls-php-code/#post-14879170)
 * > 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://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attributes)
   > [https://developers.google.com/web/updates/2011/08/Downloading-resources-in-HTML5-a-download](https://developers.google.com/web/updates/2011/08/Downloading-resources-in-HTML5-a-download)
 * I’ve tried that before, but every browser approaches it differently, so unfortunately
   this isn’t a universal solution.
 *  Thread Starter [michalrama](https://wordpress.org/support/users/michalrama/)
 * (@michalrama)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/how-to-create-a-link-that-calls-php-code/#post-14895508)
 * Hello [@corrinarusso](https://wordpress.org/support/users/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 `onclick` attribute, but how do I 
   define it when I have it written, for example, using the [PHP code snippet plugin](https://wordpress.org/plugins/insert-php-code-snippet/)?
   Thank you

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘How to create a link that calls PHP code?’ is closed to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [link](https://wordpress.org/support/topic-tag/link/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 2 participants
 * Last reply from: [michalrama](https://wordpress.org/support/users/michalrama/)
 * Last activity: [4 years, 8 months ago](https://wordpress.org/support/topic/how-to-create-a-link-that-calls-php-code/#post-14895508)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
