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 trying to fire some code when a page is edited and/or saved. This code works:

add_action( 'save_post', 'add_promoted_meta_data' );
function add_promoted_meta_data( $post_id ) {
   echo '<h1>test</h1>';

...but this code does not:

add_action( 'edit_post', 'add_promoted_meta_data' );
function add_promoted_meta_data( $post_id ) {
   echo '<h1>test</h1>';

What action would I use to combine the functionality? I ultimately need to fire code upon creating or editing a post?

Thanks in advance!

share|improve this question
up vote 0 down vote accepted

The documentation for the save_post action says:

save_post is an action triggered whenever a post or page is created or updated, which could be from an import, post/page edit form, xmlrpc, or post by email.

So, you should only need the save_post action to run the desired code when the post is changed.

share|improve this answer
Yes, but it is not firing when editing. Only when I create and then save. – graphical_force Jan 20 '14 at 23:39
If I remember correctly, the save_post action only triggers when the post's content has actually changed. Are you actually editing the content when testing this or just hitting the Update button without changing any content? – Eric Allen Jan 20 '14 at 23:46
I thought of that as well. I'm adding content. It's still not working. – graphical_force Jan 20 '14 at 23:50
Are there any other plugins installed? One of them could be interfering with the save_post action. – Eric Allen Jan 21 '14 at 0:07
I've disabled all plugins and it still does not work. When I go to create a post, it fires before I hit publish. I would imagine if I were to update a post, it would fire before I actually press update. Just by visiting that page. – graphical_force Jan 21 '14 at 0:19

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.