Reply links in RSS items
Published 4 years, 3 months past
Inspired by Jonnie Hallman, I’ve added a couple of links to the bottom of RSS items here on meyerweb: a link to the commenting form on the post, and a mailto:
link to send me an email reply. I prefer that people comment, so that other readers can gain from the reply’s perspective, but not all comments are meant to be public. Thus, the direct-mail option.
As Jonnie says, it would be ideal if all RSS readers just used the value of the author
element (assuming it’s an email address) to provide an email action; if they did, I’d almost certainly add mine to my posts. Absent that, adding a couple of links to the bottom of RSS items is a decent alternative.
Since the blog portion of meyerweb (and therefore its RSS) are powered by WordPress, I added these links programmatically via the functions.php
file in the site’s theme. It took me a bit to work out how to do that, so here it is in slightly simplified form (update: there’s an even more simplified and efficient version later in the post):
function add_contact_links ( $text ) {
if (is_feed()) {
$text .= '
<hr><p><a href="' . get_permalink($post) . '#commentform">Add a comment to the post, or <a href="mailto:admin@example.com?subject=In%20reply%20to%20%22' . str_replace(' ', '%20', get_the_title()) . '%22">email a reply</a>.</p>';
}
return $text;
}
add_filter('the_content', 'add_contact_links');
If there’s a more efficient way to do that in WordPress, please leave a comment to tell the world, or email me if you just want me to know. Though I’ll warn you, a truly better solution will likely get blogged here, so if you want credit, say so in the email. Or just leave a comment! You can even use Markdown to format your code snippets.
Update 2020-09-10: David Lynch shared a more efficient way to do this, using the WordPress hook the_feed_content
instead of plain old the_content
. That removes the need for the is_feed()
check, so the above becomes the more compact:
function add_contact_links ( $text ) {
$text .= '
<hr><p><a href="' . get_permalink($post) . '#commentform">Add a comment to the post, or <a href="mailto:admin@example.com?subject=In%20reply%20to%20%22' . str_replace(' ', '%20', get_the_title()) . '%22">email a reply</a>.</p>';
return $text;
}
add_filter('the_content_feed', 'add_contact_links');
Thanks, David!
Comments (3)
It’s a trivial tweak, but I think you could make this simpler by switching to the
the_content_feed
hook. You wouldn’t need thatis_feed()
check any more, then.Ah HA! I wasn’t aware of that hook’s existence. That is indeed an excellent suggestion. Thank you, David!
Pingback ::
theDumpsite
[…] A really good addition to an RSS feed could be a link to the commenting form or an email to reply to… […]