You are here

function hook_simple_sitemap_links_alter in Simple XML sitemap 8.2

Same name and namespace in other branches
  1. 8.3 simple_sitemap.api.php \hook_simple_sitemap_links_alter()
  2. 4.x simple_sitemap.api.php \hook_simple_sitemap_links_alter()

Alter the generated link data before the sitemap is saved. This hook gets invoked for every sitemap chunk generated.

Parameters

array &$links: Array containing multilingual links generated for each path to be indexed.

1 invocation of hook_simple_sitemap_links_alter()
SitemapGenerator::generateSitemapChunk in src/SitemapGenerator.php
Generates and returns a sitemap chunk.

File

./simple_sitemap.api.php, line 20
Hooks provided by the Simple XML sitemap module.

Code

function hook_simple_sitemap_links_alter(array &$links) {

  // Remove German URL for a certain path in the hreflang sitemap.
  foreach ($links as $key => $link) {
    if ($link['path'] === 'node/1') {

      // Remove 'loc' URL if it points to a german site.
      if ($link['langcode'] === 'de') {
        unset($links[$key]);
      }
      else {
        if ($link['alternate_urls']['de']) {
          unset($links[$key]['alternate_urls']['de']);
        }
      }
    }
  }
}