Below is the code to add social share links in WordPress RSS feed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function prefix_add_social_share_links_in_rss_feed($content) { | |
if (is_feed()) { | |
$permalink_encoded = urlencode(get_permalink()); | |
$post_title = get_the_title(); | |
$content.= '<br><br>Share: | |
<a href="http://www.facebook.com/sharer/sharer.php?u=' . $permalink_encoded . '" title="Share on Facebook" target="_blank" rel="nofollow">Facebook</a> • | |
<a href="https://twitter.com/intent/tweet?hashtags=customhashtag&text=' . $post_title . '&url=' . $permalink_encoded . '" title="Share on Twitter" target="_blank" rel="nofollow">Twitter</a> • | |
<a href="https://plus.google.com/share?url=' . $permalink_encoded . '" title="Share on Google+" target="_blank" rel="nofollow">Google+</a> • | |
<a href="http://www.linkedin.com/shareArticle?mini=true&url=' . $permalink_encoded . '" title="Share on LinkedIn" target="_blank" rel="nofollow">LinkedIn</a> • | |
<a href="mailto:?Subject=' . $post_title . '&Body=Your%20custom%20text%20goes%20here:%20' . $permalink . '">Email</a> • | |
<a href="https://getpocket.com/save?url=' . $permalink_encoded . '" title="Save to Pocket" target="_blank" rel="nofollow">Pocket</a>'; | |
} | |
return $content; | |
} | |
add_filter('the_excerpt_rss', 'prefix_add_social_share_links_in_rss_feed'); | |
add_filter('the_content', 'prefix_add_social_share_links_in_rss_feed'); |