DEV Community

Konstantin Filtschew
Konstantin Filtschew

Posted on • Updated on

Define Canonical URL in a Hugo Theme

Hugo is a static site generator, but links to your site may contain optional
params like ref=... which may produce duplicate content for search engines.
You can use canonical URL to define, which URL should be used by Google and co.

Google has a very detailed description how to consolidate duplicate
URLs
.

If you know Hugo and want just a copy a paste solution,
just add this to your head:

<head>
  ...
  <link rel="canonical" href="{{ .Permalink }}">
  ...
</head>

Enter fullscreen mode Exit fullscreen mode

This will result in an URL like:

<head>
  <link rel="canonical" href="https://qameta.com/posts/your-blog-post/">
</head>
Enter fullscreen mode Exit fullscreen mode

There is more you can do. See the full post here: https://qameta.com/posts/define-canonical-url-in-a-hugo-theme/

Top comments (0)