How to remove the default language designation from the link

My website has 3 languages. The default language is en.
Now I need to create a link to a blog page of the same language as the current page lanugage.
To link to that page I determine the current page lanugage and use it in the HTML link:

<a href="{{ $.Language.Lang | absURL }}/blog/markdown_tutorial">Markdown</a>

This works fine for the other 2 languages creating correct links. But when the current page language is en, it creates links that don’t work, e.g.:

http://localhost:1313/en/blog/markdown_tutorial

because configuration of my site does not use the language designation in the links.
To work, this link should have no language designation, like:

http://localhost:1313/blog/markdown_tutorial

How to remove the language designation from the link when the language is default?

See https://gohugo.io/methods/site/languageprefix/

But it would less fragile to do something like:

{{ with site.GetPage "/blog/markdown_tutorial" }}
  <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
{{ end }}
1 Like

I searched for this info, but could not find.
Thank you very much Joe!

Victor

1 Like

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