Spicing up you’re wordpress RSS feed

by adam on February 18, 2010

Here’s a nifty little function you can add to you’re theme’s functions.php
to append the post category link in you’re rss feed, but the same technique can be applied to add just about anything. This can be especially useful if some sites are scraping you’re content from you’re rss feed and you want to include a link back. It utilizes the ‘the_excerpt_rss’ and ‘the_content_rss’ hooks depending on how you’re rss feed is configured.

//Add a feed link back to category level page
function feed_link($content) { global $post;

foreach((get_the_category()) as $category) {

if ($category->category_parent == 0) {
$cat_name = $category->name;
$cat_ID = $category->cat_ID;
$link = get_category_link( $cat_ID );

break;
}
}
$content = $content.'<br /><a href="'.$link.'">More '.$cat_name.'  posts</a>';

return $content;
}
add_filter('the_excerpt_rss','feed_link');
add_filter('the_content_rss','feed_link');

3 comments

RSS Feeds are really very helpful and you could get site and news updates from it.,-~

by Ethan Thompson on May 20, 2010 at 9:11 am. #

RSS feeds are really great because you are always updated with the latest news or blog posts.~~~

by Abigail Moore on July 28, 2010 at 12:11 am. #

i think that RSS FEEDS should also be included on the list of the best inventions because it makes life easier for bloggers like us `;-

by Bathroom Lighting %0B on December 22, 2010 at 10:16 am. #

Leave your comment

Required.

Required. Not published.

If you have one.