Adding custom elements and XML namespaces
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
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion