I'm looking for some inspiration on the best way to run a php script away from the template. I know that the wordpress core files won't have loaded, so I am wondering what workgflow you follow when doing this?


  • What do you mean by away from the template?
    – t31os
    Feb 8 '11 at 15:30
  • I mean running a script that is inapproprate to run on the current template file. i.e, I need to sent get variables that can't be loaded on to the current page.
    – Mild Fuzz
    Feb 8 '11 at 15:33

Hi @Mild Fuzz:

Sounds like what you might be looking for is the template_redirect hook. If you add a function for that hook then you can output whatever you want and end with an exit; statement.

add_action( 'template_redirect', 'yoursite_template_redirect' );
function yoursite_template_redirect() {
  if (isset($_GET['foo']) && $_GET['foo']=='bar') {
    // Do whatever you want when $_GET['foo']=='bar'

You'll need to figure out what criteria to test for such as I showed with $_GET['foo']=='bar', but is that what you are looking for?

  • not 100% on when this will action, could you expand?
    – Mild Fuzz
    Feb 8 '11 at 15:33
  • 1
    @Mild Fuzz - Have you tried it yet? If yes, what did it do or not that you didn't want or did want? Feb 9 '11 at 19:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.