How to Create Email Notification For Every Comment on Custom Post Type

WordPress is true legit and wonderfull CMS out there that can give us many options to create our content freely. With the Custom Post Type feature, WordPress is a swiss army for blogger and news writer to create their websites.

This is the simple tutorial to create email notification for every comment on Custom Post Type. For my case, I’ll use “tips” as custom post type.

We can append our function to comment_post action. for example:

[sourcecode language=”php”]
add_action(‘comment_post’, ‘comment_email_notification’, 11, 2);

function comment_email_notification($comment_ID, $comment_approved) {
$post_type = get_post_type();
if ($post_type !== ‘tips’) {

$comment = get_comment($comment_ID);
$post_ID = $comment->comment_post_ID;
$author_ID = get_post_field( ‘post_author’, $post_ID );
$author_email = get_the_author_meta( ‘user_email’, $author_ID );
if (isset($author_email) && is_email($author_email)) {
$message = ‘New comment on <a href="’ . get_permalink($post_ID) . ‘">’ .
get_the_title($postid) . ‘</a>’;

create_function(”, ‘return "text/html";’));

wp_mail($author_email, ‘New Comment for your Article’, $message);

Took that code into functions.php in your active WordPress theme.