Links to anchor in the same page


I do not find a way to add links to anchor on a page (other than writting raw html).

Something like :

[Jump to Foo](#Foo)

## Foo

Doesn’t works because of the unique identifier added to html tag :

<h2 id="Foo:4a1318da06786ac52626178ca960109e">Foo</h2>

Thanks for help

Seeing that id I know you use the “latest and greatest” - there is shortcodes called ref and relref that fixes this. And there is an option to turn off that extra id, I think.

I suggest you look in the current /docs (start a hugo server in the docs folder) and read more abut it there ., somewhere.

Thx @bjornerik thanks too your reply i’ve found the solution:

[Foo]({{<ref "#foo" >}}) 
## Foo

My problem is: I want to supply a URL including anchor in an email. But the identifier is undesired. Why? People may be hesitant to click a link that contains a sort of hash code, because hashes and other code stuff in emails is very often used to identify WHO clicked the link in an email.

Hello @bep. I’m trying to find out about links to anchors on a page. However, I don’t appear to have a/docs folder in my Hugo installation. Where else can I find the required info?

@arlcaulkett please don’t address me by name for general Hugo questions that everone can answer.

My question was in response to a specific message that you posted where you mention a folder that doesn’t exist on my Hugo installation. If you feel that I was being unreasonable in addressing the question about your post to you, then that’s your prerogative, of course.

I realise that our internet relationship has not got off to a great start. In my defence my previous mentions of you by name were in response to automated anti-spam messages, but which appeared to be directly attributable to you. My mistake, and, for that, I apologise. I do not apologise, however, to being royally pissed off with being presented with a message telling me that I was prevented from posting for a 240 hour period.

I refer you to this tweet:

That having been said. I really like Hugo as a piece of software, and I would like to be on friendly terms with all of the people involved with it. Whaddya say?

I am also having a problem getting links to other parts of the same page to work. I tried using the ref and relref shortcodes to no avail. These are the methods I have tried:

## Foo

[Foo]({{<ref "#foo" >}})
[Foo]({{<relref "#foo" >}})
<a href="#foo">Foo</a>

In each case, the link that gets created ends up being baseURL/#foo which redirects to the homepage when clicked. I am using the Hugo Dusk theme and initially, canonifyURLs was set to true. I thought that may have been the problem, but setting it to false did not help. Currently, I am getting the desired effect by typing out the name of the page in the link:


Does anyone have an idea what setting I may need to change to get the ref shortcode working properly?

I figured out a solution so I thought I’d leave it here for anybody else looking:

<a href="{{.URL}}#foo">Foo</a>
1 Like