I'm using Views to generate a custom RSS feed. I need to add an extra tag in the header. I tried different setting in Header section of the Feed Display, but nothing gets displayed in the feed.

Could anyone explain what's the best way to do it

  • I should add that also I need also an extra <image> tag with a path to logo image inside the main <channel> section
    – zbigniew
    Jul 20 '13 at 17:59

Maybe it's because I don't know the views module well enough but I could not get views to do this at all. Instead I created a simple module that outputs an RSS feed. Use:

header("Content-type: text/xml");
print '<rss version="2.0">';

to have PHP output the correct headers.

EDIT: not sure it makes sense to just post the code but I can describe it:

1) The code below creates the page where your XML feed will live (should be in *.module file):

function xml_sender_menu() {
   $items['feed'] = array(
     'title' => 'RSS Feed',
     'page callback' => 'rss_feed',
     'access arguments' => array('access content'),
     'type' => MENU_CALLBACK,

     return $items;

2) Then in the same file create a function called "rss_feed()" (this name should be the same as the 'page callback' => 'rss_feed', in the above array) which will contain the code that produces the actual website. The function doesn't need to return anything.

3) http://cyber.law.harvard.edu/rss/rss.html contains a good readable description of the RSS specification, use Drupal API/PHP to output the data you want into the correct fields. For example I used the node's title to fill in the <title> field in RSS by doing this:

$sourcetitle = htmlspecialchars($node->title);
    print '<title>'.$sourcetitle.'</title>';

4) At the end output all the closing tags </channel> & </rss>

I don't know what data you are trying to fill your RSS feed with, so can't really be any more specific. Finally, copy/paste the output into an RSS validator to make sure you are not missing anything.

** Something I just realized: if you are adding other fields that aren't in the RSS specification, it's no longer an RSS feed. Instead you are just getting a plain old custom XML feed, don't know if that makes a difference to you.


  • could you share your entire RSS module code?
    – zbigniew
    Jul 20 '13 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.