Get rid of lastmod in sitemap

Hi guys,

I want to create my custom sitemap. I didn’t add any lastmod but hugo adds it automatically…

How can I get rid of this? :slight_smile:

Show a repo with the template you are editing.

{{ printf "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | safeHTML }}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xhtml="http://www.w3.org/1999/xhtml">
{{ range .Data.Pages }}<url><loc>{{ .Permalink }}</loc></url>{{ end }}
</urlset>

I didn’t write any lastmod line in it. But still it’s being added in the sitemap…

i can’t expose my repo yet

Then you have to reproduce the error in a repo and share it. Sharing snippets of template alone isn’t going to debug this. :slight_smile:

i just find it weird that it adds lastmod to my sitemap automatically. the date from my publishDate is being used in all my .md posts

#support is not for fielding your feelings about how Hugo works. You share your project code and get fixes.

1 Like

Hugo has a built-in Sitemap template, but if you want to get rid of lastmod from sitemap.xml then copy and paste below sitemap.xml template in layouts/_default/sitemap.xml location:-

{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
  xmlns:xhtml="http://www.w3.org/1999/xhtml">
  {{ range .Data.Pages }}
  <url>
    <loc>{{ .Permalink }}</loc>{{ with .Sitemap.ChangeFreq }}
    <changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
    <priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
    <xhtml:link
                rel="alternate"
                hreflang="{{ .Language.Lang }}"
                href="{{ .Permalink }}"
                />{{ end }}
    <xhtml:link
                rel="alternate"
                hreflang="{{ .Language.Lang }}"
                href="{{ .Permalink }}"
                />{{ end }}
  </url>
  {{ end }}
</urlset>

Moreover if need more details on how to disable or further customize sitemap.xml for Hugo website then follow this link:-

1 Like

thank you so much!!!

i had my sitemap.xml in the layouts directory instead of the layouts/_default/ directory :slight_smile:

handy website. i didn’t know about the sitemap_ignore: true in .md files. learned something new :slight_smile:

[Edited] Hugo documentation says, we can add sitemap.xml in either layouts or layouts/_default directory. But as mentioned by @short, it works only when we place in layouts/_default directory.

1 Like

Please note that sitemap_ignore: true is a custom parameter and do not come out of the box in hugo front-matter. You can add any number of custom parameters in your page front-matter say my_custom_parameter: random_value. Once you create parameters, you can access those custom parameters using page variables .Params.my_custom_parameter in hugo partials or sitemap.xml template.

1 Like

if i have sitemap.xml in layouts instead of layouts/_default it adds the lastmod automatically… even if it’s not in my sitemap template

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.