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?
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.
Post new comment