You are here

function hook_xmlsitemap_element_alter in XML sitemap 7.2

Same name and namespace in other branches
  1. 8 xmlsitemap.api.php \hook_xmlsitemap_element_alter()
  2. 2.x xmlsitemap.api.php \hook_xmlsitemap_element_alter()

Alter the content added to an XML sitemap for an individual element.

This hooks is called when the module is generating the XML content for the sitemap and allows other modules to alter existing or add additional XML data for any element by adding additional key value paris to the $element array.

The key in the element array is then used as the name of the XML child element to add and the value is the value of that element. For example:

$element['video:title'] = 'Big Ponycorn';

Would result in a child element like <video:title>Big Ponycorn</video:title> being added to the sitemap for this particular link.

Parameters

array $element: The element that will be converted to XML for the link.

array $link: An array of properties providing context about the link that we are generating an XML element for.

object $sitemap: The sitemap that is currently being generated.

1 invocation of hook_xmlsitemap_element_alter()
xmlsitemap_generate_chunk in ./xmlsitemap.generate.inc
Generate chunk.

File

./xmlsitemap.api.php, line 242
Hooks provided by the XML sitemap module.

Code

function hook_xmlsitemap_element_alter(array &$element, array $link, $sitemap) {
  if ($link['subtype'] === 'video') {
    $node = node_load($link['id']);
    $element['video:video'] = array(
      'video:title' => check_plain($node->title),
      'video:description' => isset($node->body[LANGUAGE_NONE][0]['summary']) ? check_plain($node->body[LANGUAGE_NONE][0]['summary']) : check_plain($node->body[LANGUAGE_NONE][0]['value']),
      'video:live' => 'no',
    );
  }
}