When using frameworks, we have routes where we can configure a callback functions for links, in drupal too there are menus that can be used to do the same. So i would like to know if there is a proper way in Wordpress to "do something" like call a function from functions.php when some link is clicked.

  • 1
    Depends on what you need to do I guess. Simplest version (that’s conceptually related to what you’re describing) is to create a rewrite rule (with add_rewrite_rule()) to set ‘query variables’ based on the URL. Then hook into various places to act on these variables. Such as template_redirect to redirect, template_include to render a custom template or just init to run arbitrary code. There’s other simpler options for certain functionality you might want, but it really depends on what you want to do. A specific use case might result in more useful answers. – Jacob Peattie Dec 11 '17 at 13:49
  • @JacobPeattie Thank you for your answer. Here is what i need to do: I have a custom post type (invoice), and i would like to call a function that will generate it as pdf, from a link that will be on single-invoice.php template. – Badr Dec 11 '17 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.