Send Email To WordPress Author On Post Publish

Here is a great WordPress snippet for multi author blogs. This will automatically send an email to the author of the post once it has been published.

It uses the WordPress action of publish_post which runs after the post has been published.

All you have to do is add the following into your functions.php page.

function authorNotification($post_id) {
   $post = get_post($post_id);
   $author = get_userdata($post->post_author);

   $message = "
      Hi ".$author->display_name.",
      Your post, ".$post->post_title." has just been published at ".get_permalink( $post_id ).". Well done!
   wp_mail($author->user_email, "Your article is online", $message);
add_action('publish_post', 'authorNotification');

Source: WordPress Essentials: The Definitive Guide To WordPress Hooks

Back to top

Learn how to code with Treehouse

  • Learn projects with access to 1000+ videos
  • Practice live with our Code Challenge Engine
  • Get help in our members-only forums

Start with a 7 day free trial