Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Solved: How to remove a date field from a Views RSS Feed in Drupal

Parent Feed: 

We had sailed the stormy seas, we had slayed the mighty dragon, we had ... got to the point where we were ready to launch a rather large site, but ...

Arr ... there be a problem: the RSS feed being outputted by Drupal's Views module was printing a date field, and we (or more specifically, the client) didn't want it there.

A quick Google search came up with a decent result. I implemented this and all worked ... until the shiny new site threw up some errors - because of a deprecated funtion as of PHP 5.3, namely 'ereg' has been replaced with 'preg'.

So for Drupal versions using PHP5.3+, to remove the date from your views RSS output, you need to  create a file in your theme called: views-view-row-rss.tpl.php

Then edit the line (from the default views output) from this:

print $item_elements;

to this:

$item_elements = preg_replace('<pubDate>.*</pubDate>', '', $item_elements);  // removes pubdate
$item_elements = preg_replace('<dc:creator>.*</dc:creator>', '', $item_elements);  // removes author
$item_elements = preg_replace('<category .*</category>', '', $item_elements);  // removes terms
$item_elements = preg_replace("!^\s+(\D)!m", "\\1", $item_elements);  // removes some blank lines
print $item_elements;

I've left in a few extra elements to show how to remove them as well - you can delete the lines from the above code that are not relevant to your use-case.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web