Adding custom elements and XML namespaces

Last updated on
3 January 2023

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

Adding new <channel> or <item> elements

To add new custom <channel> element use hook_views_rss_channel_elements(). To add new custom <item> element use hook_views_rss_item_elements().

The format of element definition in both cases is the same.

For example, to add new <item> element <g:id> for Google Merchant Center the most basic hook implementation could look like this:

function MYMODULE_views_rss_item_elements() {
  $elements['g:id'] = array(
    'title' => t('Google Merchant Center product ID'),
    'description' => t('An identifier of the item'),
  );
  return $elements;
}

Remember about flushing Views cache after making any changes to element definitions.

Adding new namespace

You should also define a new namespace using hook_views_rss_namespaces():

function MYMODULE_views_rss_namespaces() {
  $namespaces['g'] = array(
    'prefix' => 'xmlns',
    'uri' => 'http://base.google.com/ns/1.0',
  );
  return $namespaces;
}

Optionally you can skip namespace hook implementation - in such cases new namespace will be automatically detected and added to view's configuration form in Namespaces fieldset, where relevant URI reference should be provided (otherwise the namespace will not by added to the generated feed).

Remember about flushing Views cache after making any changes to namespace definitions.

Help improve this page

Page status: Not set

You can: