WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
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?

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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