Changing your WordPress RSS feed titles
March 6th, 2009 12 Comments
In my last post I mentioned that I'd been tweaking the feeds from my WordPress blog. Here's the detail (in case I need to redo this next time I upgrade WordPress).
The problem
The feed for the ITauthor Podcast (which is just a feed for a WordPress category called "Podcast") was coming out as ITauthor >> Podcast. It annoyed me that the podcast showed up in iTunes with those two greater than signs, or double angle brackets, chevrons, whatever you want to call them. In fact, although it looks like two characters it's actually the double right angle quote character:
» which is typically written in HTML using the character code » and in XML using the code »
My solution
The way I got rid of this may not be the easiest or best way. I search the WordPress Codex without finding out how to fix this, so in the end this is just the way I figured out how to do it. It may not be good. It may not be nice. It's certainly not pretty. All I'm saying is that it works for me.
So what I wanted to do was have a feed for my podcast category page that had the feed title "The ITauthor Podcast".
There were two tasks:
- Remove the angle quote completely in the cast of the feed for my "podcast" category page, but for other feeds change this character to a colon so that, for other categories, instead of "ITauthor >> Category", I'd have "ITauthor: Category".
- For the "podcast" category page, add "The" at the start of the feed title.
Here's what you do:
- Go into your wp-includes directory and take a backup copy of feed.php and feed-rss2.php.
Now I've moved to Dreamhost, I have the luxury of an ssh connection and a command line, which makes this very quick and easy (provided you're happy working on the command line).
- Open the feed.php file (e.g. using vi or some other plain text editor).
-
Change:
function wp_title_rss($sep = '»') { echo apply_filters('wp_title_rss', get_wp_title_rss($sep)); }to:
function wp_title_rss($sep = '»') { if (in_category('26')) { echo ' ' . trim( get_wp_title_rss('') ); } elseif ( is_archive() | is_category() | is_tag() | is_date() ) { echo ': ' . trim( get_wp_title_rss('') ); } }What this does is as follows.
For category 26 (which happens to be the number of my podcast category), it gets the category title. The empty string for an argument means that it prepends a space followed by nothing (because I don’t want a separator character), followed by a space. The second space is added because the function expects a separator character in the middle. The trim function trims away the two spaces, but we add back a single space (that's the first thing that gets echoed) otherwise the result would be "ITauthorPodcast".
For all other categories, and various other types of pages we do exactly the same, but prepend a colon followed by a space, rather than just a space. This gives us "ITauthor: Category".
For anything else (e.g. the Home Page) this function does nothing, which results in a feed title of just "ITauthor".
- Save your changes to this file.
- Open feed-rss2.php.
This is the file that creates the RSS2 feed (the default format for feeds). It's here that the category title (as generated by wp_title_rss() in the feed.php file) is appended to the blog title. So it's here we can prepend "The " to give us "The ITauthor Podcast.
- Insert an if clause into the part of the script that prints the title, so that if this is the feed for the podcast category (ID 26 on my system) it adds "The " in front of the title generated by bloginfo_rss('name') and wp_title_rss().
-
Change:
<title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>to:
<title><?php if (in_category('26')) echo 'The '; bloginfo_rss('name'); wp_title_rss(); ?></title> -
Save the file.
Potentially similar posts
- AudioBoo makes (mini) podcasting easy – September 2010
- EasyListener resurrected – June 2010
- ITauthor podcast #33 – A history of RSS – March 2010
- Podcast recommendations – March 2009
- Technical writing podcast mashup – February 2009
March 8th, 2009 at 1:48 am (#)
I've always found code snippets challenging in posts. Thanks for posting this.
May 14th, 2009 at 5:09 pm (#)
I needed to do this exact thing and your blog post really helped. I did find a method of doing it that doesn't require hacking the feed.php file, so the change doesn't get blown away every upgrade. And it also handles other RSS data besides the title, like URL and description.
You can find it all in this post http://www.reactuate.com/2009/05/14/custom-rss-feed-for-a-podcast-category/
May 16th, 2009 at 10:16 am (#)
Ron
That's great. I've never tried writing a WordPress plugin so I was fascinated to see that it looks like it's not that hard to do. Thanks for the comment.
June 28th, 2009 at 7:36 pm (#)
I just realised that my feeds had switched back to "ITauthor >> Category" and eventually realised (as Ron commented above) that I'd done an upgrade, so this change had been blown away. It's a simple enough fix but annoying when WordPress upgrade come thick and fast as they have been doing recently - and especially now when it's so easy just to click-upgrade your WordPress installation.
July 25th, 2009 at 2:47 am (#)
Thanks for the blog post - both of these were helpful to finding a solution to a similar problem.
However! You can also install a wordpress addon called 'HeadSpace' (which I highly recommend for changing page descriptions, titles, meta keywords, etc). Over at: http://urbangiraffe.com/plugins/headspace2/
Under settings > Headspace click on Page Modules, then drag-and-drop the RSS Name module from disabled to advanced.
Then click on Page Settings, then click on 'Global Settings', then click on 'advanced'. I changed the name to ": Proven Solutions for Maximum Profits" and after the feed.php code is done with it, it looks like "The BizCoach: Proven Solutions for Maximum Profits".
Cheers!
-Joshua Hughes
-Database & Software Development
-Solid Technology, Inc.
August 14th, 2009 at 7:07 pm (#)
Hey, thanks for the tip Joshua - that sounds like a really useful plugin. I'll check it out.
December 31st, 2009 at 8:38 pm (#)
i've also found that trick, but i forgot about "echo". Thanks for post.
And Happy New Year.
January 11th, 2010 at 3:06 pm (#)
Glad you found it useful.
Happy New Year!
August 10th, 2010 at 7:34 am (#)
Just found a quick way to get rid of the right angle quote character. It's based on Ron's answer above.
Add this to your functions.php file in your theme:
// Fix RSS Title
function nixRaquo() {
$title = wp_title('', false);
return $title;
}
add_filter('get_wp_title_rss', 'nixRaquo', 1);
April 25th, 2011 at 7:45 pm (#)
Corey,
I have been looking for a way to make these changes for 2 days. Found your post and was able to make some minor tweeks to make it fit to what I needed. Your post was a great and could not have come at a better time. Thank you!!!!!!
October 20th, 2011 at 9:59 am (#)
Thanks, nice workaround.
November 14th, 2011 at 10:08 am (#)
We have a problem with out blog feed name. Do you recommend this solution in our case as well? http://www.best-grocery-coupon-websites.com ... every time I see our feed name it's "Comments on: Finding the best..." I'm not sure how it ever got to be such.