Can I set canonical dynamically?

A web page should hav a canonical address (www points to url without www etc)

This works a expected when placing this in the of the page (each and every page)

<head>
    <link href="https://gowebstatic.tk/why/" rel="canonical">
</head>

I guess that w.Header is not exactly the same, but maybe related.

w.Header().Set("Content-Type", "text/html")

The difference is that “Header” takes key-value pair so I cannot set the “dynamically” with TWO value-pairs. Correct?

So my question is if there is a solution that I can set the path by sending a parameter or similar to the . Other than the usual {{.}} in the template?

<link href="path" rel="canonical">

or

w.Head().Set("link", path, 'rel="canonical")

I have search for hours but found no solution.

TIA

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