Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to have Wordpress email me whenever a Page or Post is Published?

share|improve this question

3 Answers

up vote 10 down vote accepted

There's a few plugins that handle email notifications, but they all seem to act like a subscription service for (all) WordPress users.

To notify just you when a post or page is published, it's literally a few lines of code.

function __notify_admin_on_publish( $new_status, $old_status, $post )
{
    if ( $new_status != 'publish' || $old_status == 'publish' )
        return;

    $message = 'View it: ' . get_permalink( $post->ID ) . "\nEdit it: " . get_edit_post_link( $post->ID );
    if ( $post_type = get_post_type_object( $post->post_type ) )    
        wp_mail( get_option( 'admin_email' ), 'New ' . $post_type->labels->singular_name, $message );
}
add_action( 'transition_post_status', '__notify_admin_on_publish', 10, 3 );

You can either drop this in your theme's functions.php, or save it as a plugin (which might be more appropriate, as it's not exactly 'theme' related).

share|improve this answer

Sure, you will need to use appropriate Post Status Transition hook or hooks and wp_mail().

share|improve this answer

sha -- it answers the question by contributing the knowledge that the posted solution does not work in all instances.

After 24 hours, I can update the knowledge I contributed. The solution at this location ( Notify admin when page is edited? ) works on the server where the solution posted above does not. To quote from the thread with the solution that works better in the two contexts I tried:

The original script from the wpcodex works fine:

 add_action( 'save_post', 'my_project_updated_send_email' ); 
 function my_project_updated_send_email( $post_id ) { 
    //verify post is not a revision 
    if ( !wp_is_post_revision( $post_id ) ) { 
         $post_title = get_the_title( $post_id ); 
         $post_url = get_permalink( $post_id ); 
         $subject = 'A post has been updated'; 
         $message = "A post has been updated on your website:\n\n";
         $message .= "<a href='". $post_url. "'>" .$post_title. "</a>\n\n"; 
         //send email to admin 
         wp_mail( get_option( 'admin_email' ), $subject, $message ); 
   } 
} 
share|improve this answer

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.