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.








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!
Do you know if this tweak is still working with wordpress 3.4.1?! Can’t make it work.
Yes, it should still work with 3.4.1.
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?
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.
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 !!!!!
Which contact form plugin are you using?
I actually got it now. Just edited the “$content = $content.”<br /><br /><div>”.$coolcustom.”</div>n”;” line. Perfect!
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?
Now I can stick it to those content stealers!
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
Is there a way to find out who is subscribing to your RSS feeds on WordPress?
Yes, you can use FeedBurner. In our beginner’s guide category we have a full article covering it.
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!!
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
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
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…
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
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…
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!
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.
You should be able to add as many custom fields that you want without any problem
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!
I had a plugin released a while back that eases this process:
http://ajaydsouza.com/wordpress/plugins/add-to-feed/
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.
I grab your rss. Ho ho ho. Let me begin to do this tutorial on my own :confuse:
Good ideas and post. Thanks for the Share.
Made it our featured tutorial at FAQPAL.
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.
great! thanks for this. very helpful.