Boost Blog Comment Interaction With Reply Notifications

Keep the conversation flowing to boost interaction

I’m always massively disappointed when I comment on a FANTASTIC blog post, just to find out they don’t email me when they reply to my comment.

  • I LIKE starting a conversation.
  • I LIKE seeing how you respond to my comment.
  • I LIKE being able to chat with you.

Please help this all happen!

One simple plugin can increase your conversations tenfold.

Comment Reply Notification.

Install it, use it, love it.

I consider this to be a MUST HAVE plugin for every single WordPress blog.

Don’t freak out when you see the big yellow, “This plugin hasn’t been updated in over 2 years.” message on the WordPress page. Yes, it hasn’t been updated. But no, it does not actually NEED to be updated. Some plugins are so ridiculously simple that they don’t even need updates. This is one of those.

Don’t believe me? Let’s break down the code.

Coding your own comment reply notification plugin! (It’s seriously easy.)

Here’s where I confess to you that I don’t use Comment Reply Notification. I used to, but I stopped. But the only reason I stopped was because I wanted more control over the email I was sending and wanted to send via Mandrill. That’s not going to apply for like 99% of people.

But I think the fact that I took the time to code this thing myself shows how insanely easy the code is. I got a lot of it from the Comment Reply Notification plugin, so yes, that code is still relevant. It still works. It doesn’t need to be updated.

Allow me to talk you through my code.

class NG_Comment_Reply {

	/**
	 * Constructor function
	 *
	 * Adds the actions we need
	 *
	 * @access public
	 * @since  2.1
	 * @return void
	 */
	public function __construct() {
		add_action( 'wp_insert_comment', array( $this, 'comment_notification' ), 99, 2 );
		add_action( 'wp_set_comment_status', array( $this, 'comment_status_changed' ), 99, 2 );
	}

	/**
	 * When a comment gets published, this checks to see if an email should
	 * be sent. If so, it fires the email function.
	 *
	 * @param int    $comment_id
	 * @param object $comment_object
	 *
	 * @uses   send_email()
	 * @access public
	 * @since  2.1
	 * @return void
	 */
	public function comment_notification( $comment_id, $comment_object ) {
		// This comment is not approved or it's not a reply to a parent comment -- bail.
		if ( $comment_object->comment_approved != 1 || $comment_object->comment_parent < 1 ) {
			return;
		}
		$comment_parent = get_comment( $comment_object->comment_parent );

		// If someone is replying to themselves, don't send an email.
		if ( $comment_parent->comment_author_email == $comment_object->comment_author_email ) {
			return;
		}

		// Let's send the email in all other scenarios.
		$this->send_email( $comment_id, $comment_object, $comment_parent );
	}

	/**
	 * Triggers when the status of a comment gets changed (like if we approve
	 * it later). This also determines if an email should be sent, and if so,
	 * it calls our comment_notification() method.
	 *
	 * @param int    $comment_id
	 * @param string $comment_status
	 *
	 * @uses   comment_notification()
	 * @access public
	 * @since  2.1
	 * @return void
	 */
	public function comment_status_changed( $comment_id, $comment_status ) {
		$comment_object = get_comment( $comment_id );
		if ( $comment_status == 'approve' ) {
			$this->comment_notification( $comment_object->comment_ID, $comment_object );
		}
	}

	/**
	 * Crafts the comment reply message and sends the email.
	 *
	 * @param int    $comment_id
	 * @param object $comment_object
	 * @param object $comment_parent
	 *
	 * @uses   Transactional_Message
	 * @access public
	 * @since  2.1
	 * @return void
	 */
	public function send_email( $comment_id, $comment_object, $comment_parent ) {
		$recipient = $comment_parent->comment_author_email;
		$subject   = 'Hey, there\'s a reply to your comment on Nose Graze!';

		ob_start();

		?>
		<p>Hey there, hot stuff! There's a new reply to your comment over on Nose Graze. As a reminder, here's your
			original comment on the post
			<a href="<?php echo get_permalink( $comment_parent->comment_post_ID ); ?>"><?php echo get_the_title( $comment_parent->comment_post_ID ); ?></a>:
		</p>
		<blockquote><?php echo $comment_parent->comment_content; ?></blockquote>
		<p>And here's the new reply from <strong><?php echo $comment_object->comment_author; ?></strong>:</p>
		<blockquote><?php echo $comment_object->comment_content; ?></blockquote>
		<p>You can read and reply to the comment here:
			<a href="<?php echo get_comment_link( $comment_object ); ?>"><?php echo get_comment_link( $comment_object ); ?></a>
		</p>
		<p>Let's keep the conversation going!</p>
		<?php

		$message = ob_get_clean();

		new Transactional_Message( $recipient, $subject, $message, 'comment-reply' );
	}

}

new NG_Comment_Reply();

My code is pretty heavily commented if you want to follow it. There’s one thing I’ll mention that won’t work out of the box, and that’s in the send_email() method.

Towards the end I have this line:

new Transactional_Message( $recipient, $subject, $message, 'comment-reply' );

That’s because I have another class called Transactional_Message that I use as a wrapper for all my Mandrill emails. For a more typical WordPress set up, you’d want something like:

$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $recipient, $subject, $message, $headers );

That uses the built-in WordPress mailer function.

Let your readers know you’ve replied. They’ll LOVE IT!

I often see people complaining about bloggers never replying to their comments. They feel ignored. They feel like they don’t matter.

Well here’s the thing, if you don’t have a way of notifying your readers that you’ve replied, then for all they know, maybe you didn’t reply! Most people have better things to do than regularly check back to every single post they ever commented on to see if the blogger replied.

You need to let them know.

Whether you use Comment Reply Notification, my plugin, or some other plugin, have something that will let your readers know how you’ve responded. That’s the way to keep up comments and interaction on your blog!

Photo of Ashley
I'm a 27 year old California girl living in England (I fell in love with a Brit!). I like to inject a little #girlpower into the WordPress development community by teaching women how to be coding badasses. more »

Don't miss my next post!

Sign up to get my blog posts sent directly to your inbox (plus exclusive store discounts!).

You might like these

Leave a Reply

(Enter your URL then click here to include a link to one of your blog posts.)

This site uses Akismet to reduce spam. Learn how your comment data is processed.

43 comments

    1. You should test to see how it works exactly.

      -> People do not want to be emailed about EVERY COMMENT (like if it’s not necessarily a reply to theirs). Or, at least, they don’t want that to be their only choice.

      -> If they have the option of subscribing to REPLIES to their comment, that’s perfect!

      Just make sure it’s clear. πŸ™‚

  1. Yes yes YES!!!!!!! (how many exclamation points can I use before it gets weird? LOL)
    If someone’s blog doesn’t send email notifications of replies to comments, they might as well not bother replying, cause no one will ever know.

    1. This particular plugin is only on self-hosted WordPress. I think there’s a slightly less good/convenient option on WordPress.com but I’m not totally sure.

  2. Done! πŸ˜€
    Thank you Ashley. I hate it when I have to get every comment through just to see the replies πŸ™ I’m actually writing an article for Monday, “My Top Ten Favourite NoseGraze Articles” and this one will definitely be going on there πŸ˜€ I hope you don’t mind, your blog is just filled with awesomeness lol πŸ˜‰
    Amy x

    1. There are some plugins that are literally like 3 lines of code. As long as the WordPress feature they’re based off of doesn’t change, then there’s literally nothing to change about the plugin. Even if the owner wanted to, there’s just nothing to update.

      That’s the case with this plugin. This one is more than 3 lines of code, but it gets triggered in two scenarios:

      1) When a new comment is posted.
      2) When a comment’s status gets changed from something to approved (like if it was submitted, marked as pending, then the admin approved it).

      Neither of those things have fundamentally changed in WordPress.

      Similarly, the action that happens when those two things occur (the sending of an email) is based on the WordPress “send an email” feature. That also hasn’t changed in many many years.

      The smaller and more generic a plugin is, the less likely it’s ever going to need updating. πŸ™‚

      The only times a plugin REALLY needs to be updated are:

      1) WordPress deprecates (removes) a function/feature. This doesn’t happen that often.
      2) WordPress fundamentally changes how something works. This also doesn’t happen that often.
      3) There’s a security flaw. This typically only happens with bigger, more “intrusive” plugins.

      This one is pretty basic and uses functionality that’s been around in WordPress (and unchanged) for years and years. πŸ™‚

  3. Quick question, Ashley – do you know if this also works if the post author is the one who made a comment? I downloaded the plugin and tried to do a test comment + reply, but half an hour later, the email still hasn’t showed up in my inbox. Not quite sure whether that’s something I should be worried about or just a normal part of the plugin…

    Topaz @ Six Impossible Things recently posted: Friday Poetry: β€œLovesong to the Coming Storm”
    1. Yep it will work as long as the person replying to the comment isn’t the same person who made the comment.

      You do need to make sure you actually turn the plugin on though. I think a lot of people assume they can just install it, activate it, and it will work. But it actually has a settings panel where you need to turn on the comment notifications.

    1. Simply go to Plugins > Add New in WordPress and search for “Comment Reply Notification”. Then click “Install”. πŸ™‚

  4. Does the original commenter have to click a link in their email account to confirm that they want to receive the replies? Using the one in Jetpack (I believe it is), they have to confirm, and if you reply before they have clicked this, they won’t get your reply.

  5. Thanks for this useful article. At first I tried Comment Reply Notification plugin but it seems it is not updated and drives has_cap() error, so I ignored it; but I’m interested to know how can I use your customized code? And how can I integrate your code with sendgrid?

  6. Hiya…I’ve actually tried to set this up. It seems like I have this set up correctly, but when I test it by leaving a comment as a guest visitor to the site and then respond as the site administrator it’s not actually sending out the email notification. I’m not sure what to do here. Seems like an awesome plugin. Any advise? Thanks in advance!

    1. Hi Tammy,

      If you have the settings configured correctly but you’re not getting emails, then it suggests a problem with your server or domain name settings.

      SPF records with your domain not set up correctly.
      Your server’s IP has been blacklisted by your mail provider.
      etc.

      Those are the kinds of things that help ensure email delivery from your server. Without those things, your email provider could be refusing to accept any emails from your site.

  7. is there any reason to cause the notification doesn’t work ?
    the plugin i have installed and activated it as well.
    my wordprss website can send emails without problem.
    but i still can’t receive the notification email after activating that plugin.
    any idea about this ?

Recent Posts

    Random Posts