WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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've got a custom php file that I want to call every time someone publishes a new post. How would I go about doing that? Can I write it into the functions.php of my theme?

share|improve this question
up vote 1 down vote accepted
add_action('publish_post', 'call_my_php_file');
function call_my_php_file($post_id){
share|improve this answer
so I can drop that into functions.php? nice! – Ghost9 Jan 13 '11 at 2:15
I must not be doing something right as it doesn't appear to be firing.... – Ghost9 Jan 13 '11 at 2:36
if you're writing something to the screen, you won't see it because you get redirected after this action is executed. To see if your code works add a die(); after require_once... – onetrickpony Jan 13 '11 at 2:39
Ok i used your die command and it is running the script... now the problem is that I don't know where the xml is being generated that the script is making. the php that is. It normally saves it to the folder it's in, but I don't see it. – Ghost9 Jan 13 '11 at 2:46
ah ha! It's in the admin folder. so now I just need to figure out how to set the path for the save location. Thanks! This is awesome. From this I can make it so it updates on trash and update post as well. I think... – Ghost9 Jan 13 '11 at 2:52

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.