0

7 Tips To Improve Your WordPress RSS Feed

Here is a list of 7 tips you can use to help improve your WordPress RSS feed.

Add Link Back To Original Post

One of the problems with having an RSS feed is that people can use this to easily take your content parse it and automatically publish it on their website.

There are lots of blogs that all they do is republish RSS feeds from the big blogs in your niche in an attempt to outrank the original article.

This snippet allows you to add a bit of content to the bottom of all your posts in your RSS feed to let the reader know that this content is from your website.
< ?php function feed_copyright_disclaimer($content) { if(is_feed()) { $output = ' This post was written by ‘ . get_the_author() . ‘ at ‘ . get_bloginfo(‘name’) . ‘, if you are not reading this at ‘. get_bloginfo(‘name’) .’, please show your support to the author by reading the article here…‘. get_permalink() .’.
‘;
$content = $content.$output;
}
return $content;
}
add_filter(‘the_content’,’feed_copyright_disclaimer’);
?>

Add Text And Image To Your RSS Feed

You might want to add text to the bottom of your RSS feed this can be used as a place to add copyright information or advertisements, whatever you want to add to the bottom of the RSS feed just use the below snippet.

< ?php function custom_rss_feed_content($content) { if(is_feed()) { $output = " Thanks for reading this article view more at http://www.paulund.co.uk “; $content = $content.$output; } return $content; } add_filter(‘the_content’,'custom_rss_feed_content’);

This adds the message at the end of all your content, but will only appear in your RSS feed. This functionality can also be used to add ad banners to the top of your RSS feed.
< ?php function custom_feed_ad_banner($content) { if(is_feed()) { $output = "
“;
$content = $output.$content;
}
return $content;
}
add_filter(‘the_content’,’custom_feed_ad_banner’);
Include Custom Fields In RSS Content

WordPress has the ability to add custom fields to any post, these fields allow you to store extra data about the post without it having to go into the content.

But custom fields won’t appear in your RSS feed because this will only display your content, so you could miss important information for your RSS readers.

Here is a WordPress snippet to add to your functions.php file to display custom fields in your RSS feed.

function fields_in_feed($content) {
if(is_feed()) {
$post_id = get_the_ID();
$output = ‘

Find me on

‘;
$output .= ‘
Facebook: ‘ . get_post_meta($post_id, ‘facebook_url’, true) . ‘
‘;
$output .= ‘
Google: ‘ . get_post_meta($post_id, ‘google_url’, true) . ‘
‘;
$output .= ‘
Twitter: ‘ . get_post_meta($post_id, ‘twitter_url’, true) . ‘
‘;
$output .= ‘

‘;
$content = $content.$output;
}
return $content;
}
add_filter(‘the_content’,’fields_in_feed’);

Learn more about custom fields in your RSS Feed.

Add Post Featured Images To RSS Feed

One thing about your RSS feed is that the user will not get to your information from your website, so if you have a post image thumbnail they will not see it from your RSS feed unless it is added to your post. So we can take the RSS hooks we learnt in the previous post and use this to add your post image thumbnail to the post.

Below is the code snippet which will get the current post id and then get the post image thumbnail for this current post and then uses the_excerpt_rss and the_content_rss hooks to add this into the RSS feed.

function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = ‘
‘ . get_the_post_thumbnail($post->ID) .

‘ . get_the_content();
}
return $content;
}
add_filter(‘the_excerpt_rss’, ‘rss_post_thumbnail’);
add_filter(‘the_content_feed’, ‘rss_post_thumbnail’);

Learn more about adding featured images to RSS feed.

Add Feed Only Content

With WordPress you can use a shortcode in your normal posts for RSS only content, below is a WordPress snippet to use for this functionality.

Add the following into your functions.php file to create the shortcode.
function rssonly_content( $atts, $content = null) {
if (!is_feed()) return “”;
return $content;
}
add_shortcode(‘rssonly’, ‘rssonly_content’);

Now we can use this in the content of your posts, at the end of your posts put the following shortcode.

[rssonly]Thanks for reading this RSS post, please visit http://www.paulund.co.uk to view more useful snippets.[/rssonly]

When this post is published on your blog you won’t see this content but if you go to your RSS reader you will see this content at the end of the post.

Learn how to create a RSS feed only shortcode.

Exclude Categories From RSS Feed

Below is a snippet you need to add to your functions.php page which will run before the get posts method. It will check to see if the request is from the RSS feed if so then it will exclude a category from your RSS feed.

// Custom Feed Query
function customFeedquery($query) {
$categoryId = 1; // Change ID to the excluded ID
if(is_feed()) {
$query->set(‘cat’,’-’.$categoryId);
return $query;
}
}
add_filter(‘pre_get_posts’, ‘customFeedquery’);

Learn more about excluding categories from the RSS Feed.

Disable Your RSS Feed

I know this is a strange one to include in a list of useful snippets you can use on your RSS Feed, but some people may want to completely disable the RSS Feed on their WordPress blog. For this situation you can use the following snippet.

function fb_disable_rss_feed() {
wp_die( __(‘Feed is not available please return back to the
homepage!’) );
}
add_action(‘do_feed’, ‘fb_disable_rss_feed’, 1);
add_action(‘do_feed_rdf’, ‘fb_disable_rss_feed’, 1);
add_action(‘do_feed_rss’, ‘fb_disable_rss_feed’, 1);
add_action(‘do_feed_rss2′, ‘fb_disable_rss_feed’, 1);
add_action(‘do_feed_atom’, ‘fb_disable_rss_feed’, 1);

Learn more about disable RSS.

This article was original wrote on 7 Tips To Improve Your WordPress RSS Feed


 

Leave a reply