Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

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 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 at 23:46
    
I thought of that as well. I'm adding content. It's still not working. –  graphical_force Jan 20 at 23:50
    
Are there any other plugins installed? One of them could be interfering with the save_post action. –  Eric Allen Jan 21 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 at 0:19
show 2 more comments

Your Answer

 
discard

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.