0

I am trying to generate Sitemap for my site using Simple XML Sitemap module. I have checked the Documentation for Extending the module features. Since I am newbie to Drupal 8, I am in confusion how to get this achieved. tried some hooks but failed it may be my lack of understanding regarding drupal8 module development. Can anyone help me to get this done. What are the namespaces I should add to my custom module.

Currently my URLs are generated like www.mysite.com/country/india but I want it to be like www.mysite.com/country/india/ since I use trailing slash with URLs.

I've used htaccess to add trailing slash to URLs with 301 redirect.

0

You can use hook_simple_sitemap_links_alter() to change the links generated before the sitemap is saved.

function example_simple_sitemap_links_alter(&$links) {
  global $base_url;
  foreach ($links as $key => $link) {
    if ($links[$key]['url'] != $base_url . '/') { // Excluding base url
      $links[$key]['url'] = $link['url'] . '/'; // Here Trailing slash will be added
    }
  }
}

Before using the hook:

enter image description here

After using the hook:

enter image description here

-1

have a look at this ... it does not do exactly what you want but could be a good place to start.

  hook_sitemap_menu_tree_main_alter(array &$menu) {
      /**@var \Drupal\Core\Menu\MenuLinkTreeElement $menuLink **/
     foreach ($menu as $menuLink) {
       dump($menuLink); <-- do stuff with this 
     }
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.