0

I'm trying to create a very simple alert for each time a post is created or updated with the below...

add_action( 'save_post', 'updatedAlert' );
function updatedAlert() {
  echo '<script>alert("post updated!");</script>';
}

The moment I drop this in I get "headers already sent" in both post.php and pluggable.php.

Am I missing something obvious? It seems like there shouldn't be anything else to it!

Any advice appreciated.

  • What I'm trying to achieve is a popup to confirm to the user that the post they have edited or updated has been saved as some users are missing it. I was hoping if I could just tap into the save_post hook then it would be a quick way to do it! – greypiglet Jan 27 '15 at 9:24
0

Saving post doesn't just happens. Either you are submitting a form or ajax request, which spins up new copy of WP core, which does the saving. Typically that process isn't meant to produce output and isn't handling it accordingly.

Depending on what you want to accomplish you will have to either use pure JavaScript for solution or store the message during saving persistently and output it at more appropriate point in the process.

  • Thank you for this. What I'm trying to achieve is a popup to confirm to the user that the post they have edited or updated has been saved as some users are missing it. I was hoping if I could just tap into the save_post hook then it would be a quick way to do it! – greypiglet Jan 27 '15 at 9:24

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.