Error message

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.

Drupal - Views RSS Feed Title Customization with Preprocess


Creating an RSS feed with Views in Drupal is easy as pie. You can add contextual arguments to your View to provide many different types of feeds. You can even set up custom titles based on the contextual filter arguments all without writing a line of code! Amazing.

However, sometimes we need to get our hands dirty to get our RSS Feed Titles to show up the way we want. Luckily there is template_preprocess_views_view_rss() which allows us to dynamically make custom titles for our View's RSS Feeds.

In our theme's template.php file we can add this:

 * Implements template_preprocess_views_view_rss().
function MY_THEME_zen_preprocess_views_view_rss(&$vars) {
  if ($vars['view']->name == 'my_view_machine_name') {
    $vars['title'] = 'My Custom Title';

Then after we flush our Theme Registry cache, and visit the RSS feed URL for the view, we'll see our custom title on the feed.

Of course we would probably set up some booleans to make decisions about what to set our title to, this was just the simplest example. Please note, I wasn't able to get the Devel module's dpm function to work in side this preprocessor, so I had to use this command instead, and then visit my actualy Drupal home page to get the message to display with debug info:

drupal_set_message('<pre>' . print_r($vars, true) . '</pre>');

Replace 'my_view_machine_name' with, you guessed it, your view's machine name. A view's machine name can be located at admin/structure/views, then hover your mouse over the 'edit' link next to your view, that will display the URL for your view, the machine name will be in the URL, for example:

We still love you RSS, even though you are dying a slow death.

Add new comment