Reply links in RSS items

I’ve added a couple of links to the bottom of RSS items here on meyerweb: a link to the commenting form, and a mailto: link to send me an email reply.


This content originally appeared on Thoughts From Eric and was authored by Eric Meyer

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_feed_content', 'add_contact_links');

Thanks, David!


This content originally appeared on Thoughts From Eric and was authored by Eric Meyer


Print Share Comment Cite Upload Translate Updates
APA

Eric Meyer | Sciencx (2020-09-04T19:57:40+00:00) Reply links in RSS items. Retrieved from https://www.scien.cx/2020/09/04/reply-links-in-rss-items/

MLA
" » Reply links in RSS items." Eric Meyer | Sciencx - Friday September 4, 2020, https://www.scien.cx/2020/09/04/reply-links-in-rss-items/
HARVARD
Eric Meyer | Sciencx Friday September 4, 2020 » Reply links in RSS items., viewed ,<https://www.scien.cx/2020/09/04/reply-links-in-rss-items/>
VANCOUVER
Eric Meyer | Sciencx - » Reply links in RSS items. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/09/04/reply-links-in-rss-items/
CHICAGO
" » Reply links in RSS items." Eric Meyer | Sciencx - Accessed . https://www.scien.cx/2020/09/04/reply-links-in-rss-items/
IEEE
" » Reply links in RSS items." Eric Meyer | Sciencx [Online]. Available: https://www.scien.cx/2020/09/04/reply-links-in-rss-items/. [Accessed: ]
rf:citation
» Reply links in RSS items | Eric Meyer | Sciencx | https://www.scien.cx/2020/09/04/reply-links-in-rss-items/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.