You are here

function hook_simple_sitemap_links_alter in Simple XML sitemap 8.3

Same name and namespace in other branches
  1. 8.2 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

string $sitemap_variant:

1 invocation of hook_simple_sitemap_links_alter()
QueueWorker::generateVariantChunksFromResults in src/Queue/QueueWorker.php

File

./simple_sitemap.api.php, line 22
Hooks provided by the Simple XML Sitemap module.

Code

function hook_simple_sitemap_links_alter(array &$links, $sitemap_variant) {

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

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