Overriding Drupal's Default RSS Feed Icon
By default, a number of Drupal themes (including Garland) output an RSS feed icon
at the bottom of pages which generate a feed. The feed icon is generated because of the existence of the following code in the page.tpl.php file
<?php print $feed_icons ?>But what if you want a different looking icon? Maybe something larger, or a different color?
Well, there are a couple of ways to achieve this:
- The not-so right way
- The right way
1. The not-so right way
Drupal's default RSS feed icon image is located in your site's folder structure at 'misc/feed.png'. The not-so right way to change it is to simply swap this feed.png image for another feed icon image (just making sure to also name the new image feed.png).
This method will work, but is not recommended. The reason being, that you are effectively overwriting a core file. When you do an upgrade of Drupal, your new feed.png image will be replaced with the original feed.png image and you will need to update it again. This is clearly not a good idea if you have lots of sites or are doing sites for clients who do not know how to do such updates, and ultimately it's just an all round messy solution.
So, a far better solution would be one where we do not alter any core stuff, and the new feed icon remains in place even after an upgrade...this is the right way.
2. The right way
The first thing we need to do is find out what function Drupal is using to output the feed icon. So, go over to Drupal API, and do a search for feed_icon. The search should return one result - theme_feed_icon. This is exactly what we're after. Anytime you see the word 'theme_' at the beginning of a function it means that we can override the function - which is what we want to do in this case.
The functions for Drupal 5 and Drupal 6 are as follows:
Drupal 5 (http://api.drupal.org/api/function/theme_feed_icon/5)
<?php
function theme_feed_icon($url) {
if ($image = theme('image', 'misc/feed.png', t('Syndicate content'), t('Syndicate content'))) {
return '<a href="'. check_url($url) .'" class="feed-icon">'. $image. '</a>';
}
}
?>Drupal 6 (http://api.drupal.org/api/function/theme_feed_icon/6)
<?php
function theme_feed_icon($url, $title) {
if ($image = theme('image', 'misc/feed.png', t('Syndicate content'), $title)) {
return '<a href="'. check_url($url) .'" class="feed-icon">'. $image .'</a>';
}
}
?>Now that we've found our function, just do the following:
1. Create your new feed icon image, and save it to your theme's images folder at '/sites/all/themes/yourthemename/images/feed.png'.
2. Copy the function for whichever version of Drupal you are using, and paste it into your theme's template.php file (you will not need the opening and closing PHP tags - just the function).
3. Replace the word 'theme' at the beginning of the function name with the name of your own theme, like so:
function mydrupalblog_feed_icon($url) {
if ($image = theme('image', 'misc/feed.png', t('Syndicate content'), t('Syndicate content'))) {
return '<a href="'. check_url($url) .'" class="feed-icon">'. $image. '</a>';
}
}4. Finally, replace the path to the original feed icon with the path to your new feed icon, like so:
function mydrupalblog_feed_icon($url) {
if ($image = theme('image', '/sites/all/themes/mydrupalblog/images/feed.png', t('Syndicate content'), t('Syndicate content'))) {
return '<a href="'. check_url($url) .'" class="feed-icon">'. $image. '</a>';
}
}Drupal will now override the default feed icon and output your new feed icon in its place. As the change is being made in your theme's template.php file and the new image is in your images folder, it will not be overriden when you upgrade to a newer version.





Hi, I'm Laurence and this is my Drupal blog.
Don't Make Me Think!
Pro Drupal Development
PHP Cookbook
Will You Please Be Quiet, Please?
An addition to make it even 'better'... Instead of hardcoding the path to your theme you can do this...
<?php$image = theme('image', drupal_get_path('theme', 'mydrupalblog') . '/images/feed.png', t('Syndicate content'), t('Syndicate content'));
?>
The advantage of this is that if you decide to move the theme to a different folder (eg a site-specific multisite install), the path will still resolve to the correct image folder.
See this function:
http://api.drupal.org/api/function/drupal_get_path/5
This is the kind of wonderfully helpful tip that should be in the Drupal.org handbooks. Well written and clear enough that n00bs can "get" it. Very nice!
Always glad to read your blog.
It's shade that you don't write it more frequent.
Anyway, nice article.
*Delayed reaction*
@Nicholas - thanks for the tip :)
@Laura + Drupal Theme Garden - thanks! I do try to post as often as possible, but as you can see by this comment reply sometimes things take a looooong time.
Nicholas Thompson is correct.
Let me improve slightly on his idea...
<?php$image = theme('image', path_to_theme() . '/images/feed.png', t('Hello, I will feed you'), t('Hello, I will feed you'));
?>
Nice tip :). You give good explanation especially when you called it 'The right Way'.
Is there a way to remove the RSS feed completely? I have looked all over and this is the closest I have got.
You can remove the feed icons by editing the page.tpl.php file in your template and removing the "print $feed_icons" line.
Is there a way to specify different icons for different types of feeds? I would like to visually distinguish my commentrss feed from the regular site feed. I'm using Garland_dropmenu in D6.
Hi,
I was looking some clues on how to change the default feeds on Drupal, and I found your post.
It's not what I was looking for, but I thought I should subscribe to your blog and I run into the same problem that I have. :)
So, when adding a subscription in Google Reader by typing just the URL (http://mydrupalblog.lhmdesign.com/) Google offers me to subscribe to the comments feed instead of the posts feed. My guess is it that feeds are simply sorted alphabetically.
Of course, the easiest way would be to give the correct feed to Google, but still some users might not be able to figure out what's going on, so it would be nice to have some solution for this.
Any idea how to change this?
the default regions are disappearing when i write custome regions..please tel me how to add custom regions to the default regions ,please help me.
Thanks
Deepthi
Nice tips. It come handy just needed to override drupal default rss feed icon.
Offline drupal api in iPhone
Thanks for taking the time for posting this, you've helped me save some!
If you're using a subtheme for Zen and following the great example from Caroline above, remember to change path_to_theme to path_to_subtheme
This is how it looks for me in template.php for a Drupal 5 Zen subtheme:
function phptemplate_feed_icon($url) {if ($image = theme('image', path_to_subtheme() . '/images/feed.png', t('Subscribe by RSS'), t('Subscribe by RSS'))) {
return '<a href="'. check_url($url) .'" class="feed-icon">'. $image. '</a>';
}
}
Post new comment