I came across this post https://ethanmarcotte.com/wrote/replyin/ where author says he added Reply via email link at the end of each post in RSS feed so people have this option to respond via email
In his feed (XML format) it looks like this
<p><a href="mailto:<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cba7a2b8bfaea5aeb9e0b9b8b88baebfa3aaa5a6aab9a8a4bfbfaee5a8a4a6">[email protected]</a>?subject=Reply%20to:%20“Bookiversary.”">Reply via email</a></p>
I am using Underscores and it has several default feed templates that come with WP install. I checked WP Codex https://codex.wordpress.org/Customizing_Feeds and didn’t find anything specific on how to modify templates to add this feature.
Question: is this done by modifying RSS templates? If so, which one and how?
Update: Based on @birgire suggestion to use the_content_feed filter, the following code adds email address at the end of my RSS feed (as per XML view)
// add custom content to all feeds
function add_content_to_all_feeds($content) {
$after = '<p><a href="mailto:<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3159545d5d5e715c50585d1f525e5c">[email protected]</a>">Reply via email</a></p>';
if (is_feed()) {
return $content . $after;
} else {
return $content;
}
}
add_filter('the_content_feed', 'add_content_to_all_feeds');
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
This should most likely be enough:
function add_content_to_all_feeds( $content ) {
$after = '...';
return $content . $after;
}
add_filter( 'the_content_feed', 'add_content_to_all_feeds' );
without the is_feed() check.
I am wondering what are those question mark and percent signs in
?subject=Reply%20to:%20“Bookiversary.” ?
This is so called URL encoding where %20 means space.
Also can adding ‘reply by email’ option to feeds cause lots of email
spam?
It might, but some bots don’t even need to scan your site for emails, to spam you.
They can just guess the most likely emails from your domain name, e.g.
<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3d6cbd2dec3dfd6f3d6cbd2dec3dfd69dd0dcde">[email protected]</a>, <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="71181f171e311409101c011d145f121e1c">[email protected]</a>, ...
and try to spam directly.
Probably also guess it from the public usernames.
You could also link to your spam protected contact form instead.
Consider using an email account, with a good spam protection, regardless.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0