Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to Add Content and Completely Manipulate Your WordPress RSS Feeds

Last updated on by
Follow WPBeginner on YouTube
How to Add Content and Completely Manipulate Your WordPress RSS Feeds

A while back we shared how you can control your WordPress RSS Footer with a use of a famous plugin called RSS Footer by Joost. While the plugin is great, but it is very limited. You can only add text to the footer, and it is always the same text displayed on each post’s footer. What if you want to display different text for each post in your RSS post? What if you want specific posts to have a different title in RSS Feeds? What if you want to display a specific custom field in your RSS Feeds? Well this is why we present you this article which will show you how to add any type of content in your WordPress RSS Feeds. This hack will put you in control of your WordPress RSS Feeds and you can manipulate it in anyway you want.

Note: This hack is not for beginners. Only users who feel comfortable with editing functions.php file and have some knowledge of php should try this. Beginner users should either use the plugin mentioned in the article above, or consult professionals like us to do it for you.

1. Add a Custom Field to your WordPress RSS Footer

In this first example, we will show you how you can use custom field to display specific text/object in your WordPress RSS Feed. This trick will allow you to show different text, advertisement, image, or anything else for each post. First open your functions.php and paste the following codes in the php tags:

function wpbeginner_postrss($content) {
global $wp_query;
$postid = $wp_query->post->ID;
$coolcustom = get_post_meta($postid, 'coolcustom', true);
if(is_feed()) {
if($coolcustom !== '') {
$content = $content."<br /><br /><div>".$coolcustom."</div>
";
}
else {
$content = $content;
}
}
return $content;
}
add_filter('the_excerpt_rss', 'wpbeginner_postrss');
add_filter('the_content', 'wpbeginner_postrss');

Now most of you are wondering how this code is functioning. So here is an explanation. We create a function called wpbeginner_postrss which runs a global wp_query to search in each post if a custom field called “coolcustom” is defined. If Cool Custom is defined then it shows the value after the post content. If there is no custom field defined, then the function by default shows just the post content and nothing else. We use the variable $content to display content. We are using if(is_feed) function and adding the custom text or other content to the main post content itself which you can see by the second filter. But it will only be displayed in the RSS Feeds due to our user of if(is_feed) function. By doing it this way, we avoid all the compatibility issues.

Some of you will say but you just did what RSS footer plugin does with a function. Yes and NO. Yes we are adding the code at the footer of the post, but this text is not the same exact text for each post. It is different because you specify different text for each post via custom fields. This trick will be very handy to comply with the new FTC guidelines for blogs that have all different type of posts.

2. Adding Additional Text to Post Titles in RSS

Does your blog have guest posts, sponsored posts, and review posts? Well if you do then you will find this very useful. Some bloggers have custom styling to display each different type of post, so their users can distinguish between them. But when these posts go in a reader, all the stylings are gone. That is when this trick comes in handy. In this trick we will add any text either before or after the title.

For example if your title was “Commercial WordPress Theme – StudioPress” and it was a sponsored post, then you can change it to “Sponsored Post: Commercial WordPress Theme – StudioPress”. Same if someone wrote a guest post etc.

To accomplish this, open your functions.php file and add the following code in there:

    function wpbeginner_titlerss($content) {
    global $wp_query;
    $postid = $wp_query->post->ID;
    $gpost = get_post_meta($postid, 'guest_post', true);
    $spost = get_post_meta($postid, 'sponsored_post', true);

    if($gpost !== '') {
    $content = 'Guest Post: '.$content;
    }
    elseif ($spost !== ''){
    $content = 'Sponsored Post: '.$content;
    }
    else {
    $content = $content;
    }
    return $content;
    }
    add_filter('the_title_rss', 'wpbeginner_titlerss');

Explanation for the code:

We are using the function called wpbeginner_titlerss which runs a global wp_query to search in each post if it contains either $gpost or $spost. These two elements are basically looking for two specific custom fields called “guest_post” or “sponsored_post”. If anyone has these custom fields added with a value true, then the code will add it in the text. If not then you will just see the normal title. You can see first the code looks for if $gpost is true, if that is not true whether $spost is true. If that is not also not defined, then it displays normal content. But if either one of them was true, then it displays the different text you specify here. We are using $content string to display the post title.

Now that was just displaying custom fields in the title. Do you want to display Category name on each title? Well then you should simply paste the following code in your functions.php file:

function wpbeginner_cattitlerss($content) {
$postcat = "";
foreach((get_the_category()) as $cat) {
$postcat .= ' ('.$cat->cat_name . ')';
}
$content = $content.$postcat;
return $content;
}
add_filter('the_title_rss', 'wpbeginner_cattitlerss');

Explanation: We are using the function wpbgeinner_cattitlerss to get the category ID for each post and then displaying that right next to the title. So if the title is “Get Contact Form 7″ now it would be “Get Contact Form 7 [Plugins]”. You can see that there is no if then variable in this code. We use $content for the main title and $postcat variable to define the category name. You rearrange that if you like.

3. Add Same Text on all Posts in RSS

If you just want to add the same text then you might as well use the plugin called RSS Footer by Joost because it is easier. But if you want to do it yourself this is how you do it. Open your functions.php file add the following code:

function wpbeginner_postrss($content) {
if(is_feed()){
$content = 'This post was written by Syed Balkhi '.$content.'Check out WPBeginner';
}
return $content;
}
add_filter('the_excerpt_rss', 'wpbeginner_postrss');
add_filter('the_content', 'wpbeginner_postrss');

Explanation: We are calling a function wpbeginner_postrss to add in each post a content before the post saying This Post was written by Syed Balkhi and after the content Check out WPBeginner. But we add the function if(is_feed), so it will only be displayed in RSS Feeds.

This would be very helpful if you wanted to sell ads on specific posts in RSS, add custom FTC guidelines or just wanted to have more control over your RSS Feeds.

Source: We used Joost’s RSS Footer plugin for a lot of guidance in writing this tutorial. The title RSS hack part we got from a French tutorial site and we added our own variables and gave it the ability to be custom titles per custom field.


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »
  • http://www.abritandabroad.com/ Macca Sherifi

    On your RSS feed you’ve got a real simple “To leave a comment please visit [Post Title] on WPBeginner.”

    How do I replicate this? In your code that you’ve supplied, presumably I have to change “coolcustom”, but which one do I edit specifically?

  • Lapan

    Hi.
    If I have in post:
    [text1]Text one[text1]
    [text2]Text two[text2]

    How do I return text2 shortcode in rss only?

  • Gretchen Louise

    I’m trying to use the third option to add the Digg Digg plugin’s buttons to the bottom of my RSS feeds. Any suggestions on editing the content to incorporate PHP rather than just text?

  • brandy

    I am trying to use this to implement CSS disclosure buttons in my feed, but I *cannot* figure out how to get it into the description. I have code of what I tried (2 different functions for the excerpt & the post). i hate how the buttons show up in the excerpt and i don’t think it’s necessary. help? :)

    • http://www.wpbeginner.com Editorial Staff

      Your feed doesn’t load your template’s CSS, so you would have to use inline CSS.

  • Matt

    I really appreciate you sharing this information with us. I have implemented this on my site now…I always really liked how it looks in your “weekly” emails that I receive.

    I think that it looks very professional and of course it is gonna help fight back against those content scrapers (thieves).

    Again, well written code, and very useful advice. Thank you!

  • http://www.facebook.com/profile.php?id=1276888525 Etienne Bretteville

    Do you know if this tweak is still working with wordpress 3.4.1?! Can’t make it work.

    • http://www.wpbeginner.com Editorial Staff

      Yes, it should still work with 3.4.1.

  • http://adambaney.com/ Adam

    Great info! One question…  on #1 Add a Custom Field to your WordPress RSS Footer, for some reason the content/custom field is displayed twice. Any idea why?

    • http://www.wpbeginner.com/ wpbeginner

      No idea why. Have to see your code to tell that. Our code seemed to work fine when we installed it on a client’s site. 

  • rahul

    I have problem that in my site if someone fills a contact us form then his all personal info is displayed in rss feed and any user can see it
    plz help !!!!!
     

    • http://www.wpbeginner.com/ wpbeginner

      Which contact form plugin are you using?

  • thehifly

    I actually got it now. Just edited the “$content = $content.”<br /><br /><div>”.$coolcustom.”</div>n”;” line. Perfect!

  • thehifly

    Adding the additional text works great but I’m trying to have the RSS to show only that custom field (for example the “coolcustom”) as the post’s description. Get rid of the actual text of the post. Is that possible?

  • TheNerdyNurse

    Now I can stick it to those content stealers!

  • scot

    Hi, I’m looking to add two fields to my ‘full’ rss feed. One which displays the author of the post and the other which displays a list of the taxomonies, if any, that the post is in. So let’s say the author is JohnR and the post is in the NFL, Raiders and Jets taxonomies, the RSS would have two additional fields:

    JohnR
    NFL, Raiders, Jets

    Can someone point me in the right direction to get this done?

    – Scot

  • http://drdianehamilton.wordpress.com Diane

    Is there a way to find out who is subscribing to your RSS feeds on WordPress?

    • http://www.wpbeginner.com Editorial Staff

      Yes, you can use FeedBurner. In our beginner’s guide category we have a full article covering it.

  • http://agilworld.com Agilworld

    Thanks for sharing…

    Your tutorial is useful to me for verify the Technorati claim token! It worked nicely. I was looking for an effective way to verify it and found articles that discuss about that. But most of it, is not effective. And in the end, thought in my mind how add extra text in each footer post RSS feeds, Great! I found a smart way through your article, Thanks!!

  • http://thingstodoincalifornia.info/southbay Juri

    Hi,
    your code to add Custom Fields to RSS works great!!!! Thanks!
    I’m wondering if there is a way to edit the position and not to show the custom fields in the footer but above the title, or under the title, or etc… Is there a chance to add the tag “style” and so use some css?
    Thank you very much

  • http://thingstodoincalifornia.info/southbay Juri

    Add a Custom Field to your WordPress RSS Footer:
    THANKS Your code works perfectly. I have a question: How can I edit the position to show custom field up before the title or just after the title?
    I tried to edit the code here:
    $content = $content.””.$coolcustom.”
    “;
    I can remove the br tags and it works but where can I add style and css?

    Thanks for your great help

    • http://www.wpbeginner.com Editorial Staff

      You would have to use inline styling for the RSS to work on all different readers. To add it before, you will add it like $coolcustom.$content and then add div tags using quotation where you like…

  • Robert Simpson

    Hi,

    I’m trying to find a way to use a custom field to EXCLUDE a post from the RSS feed.

    Any ideas?

    Cheers,
    Robert

    • http://www.wpbeginner.com Editorial Staff

      The easiest solution would be to post it in a separate category and exclude that category from RSS Feeds with the use of Advanced Category Plugin…

  • Zach

    Hey, thanks for the tutorial. It worked perfectly. Had a quick question though – after I get the extra content to load into the RSS Feed (for example if I’m viewing it in Safari), when I actually embed the RSS Feed on a website, that extra info goes away. Do you have any idea why that would happen? It’s been about 4 days as well – and I’ve tried clearing my cache several times. Thanks!

  • kiki

    Thanks for this so far! I haven’t been able to find much on adding custom fields to the RSS feed until now.

    Would it be difficult to add multiple custom fields with the code from section 1? I have an event listing website with custom fields for each post I want to display in the RSS, i.e. “Venue,” “Event Date,” “Address,” et al.

    • http://www.wpbeginner.com Editorial Staff

      You should be able to add as many custom fields that you want without any problem :)

      • Kiki

        Sorry, I’m a bit of a novice, but what would the code look like to get the multiple custom fields. I’ve tried playing with a few configurations of the code so far but it keeps resulting in errors. One field is working great though!

  • http://ajaydsouza.com/ Ajay

    I had a plugin released a while back that eases this process:

    http://ajaydsouza.com/wordpress/plugins/add-to-feed/

    • http://www.wpbeginner.com Editorial Staff

      Ajay but does your plugin allows one to add custom fields in the RSS Text? Because it just seems like that it has the exact same functionality that Joost’s RSS Footer Plugin has which is not what this article is showing. What if you need to display different FTC texts for each post, then plugins like yours and RSS Footer would fail because they show the same text on each post. With this, one can set different ways: For example, if custom field this: Display that otherwise display the default copyright or something like that.

  • http://topan.web.id Topan

    I grab your rss. Ho ho ho. Let me begin to do this tutorial on my own :confuse:

  • http://www.faqpal.com FAQPAL

    Good ideas and post. Thanks for the Share.

    Made it our featured tutorial at FAQPAL.

  • http://notagrouch.com Oscar

    This is great, it should help out a lot when trying to do quick little customizations. Little bite-sized tips like this are very helpful. I’ve seen people put some of the social media icons at the bottom too, to add to digg, and su and stuff.

  • http://human3rror.com John (Human3rror)

    great! thanks for this. very helpful.