Adding a ‘comment via email’ convenience link.

Use GeneratePress Elements/Hooks to add a comment via email convenience link.

Web UI.

Have you seen this around?

‘Comment via email’ link available towards the end of every post.

Let’s implement it.

  • Create a new Hook Element.
  • Allow PHP execution.
  • Select the generate_after_entry_content hook.
  • For display locations, select All Singular.
  • Use the following snippet for the hook body.
<a href="mailto:<?php echo get_the_author_meta('user_email'); ?>?subject=Comment on '<?php echo get_the_title(); ?>'&body=Post link: <?php echo get_permalink(); ?>">Comment via email</a>.

And that’s it! Voila! Add some CSS sprinkles for pretty things. There’s surely a more vanilla way to do this, but I have GeneratePress with GenerateBlocks at hand, so that’s what I picked.

RSS feed.

Finally, you want your readers to be able to use the convenience link too! Use the_content_feed hook and add to the feed content.

add_filter( "the_content_feed", "feed_comment_via_email" );

function feed_comment_via_email($content)
{
   $content .= "<p><a href=\"mailto: " . get_the_author_meta('user_email') . "?subject=Comment on '" . get_the_title() . "'&body=Post link: " . get_permalink() . "\">Comment via email</a>.</p>";
   return $content;
}

Now let’s check it out:

Golden!

0

Comment via email.