How to add cannonical URL to a blog?

Hey,
I was wondering how to add a Canonical URL or Change the meta tag to canonical_url to signify this post was first published elsewhere (like on my own blog). It’s a bit confusing and I want google to understand that this is not a duplicate post hurting the SEO. Thanks :slight_smile:

Hi @hrittik ,

this tutorial should help you solve your issue:

https://blog.concannon.tech/tech-talk/hugo-canonical-url/

Hi @iaeiou,
I went through the post but my chosen Hugo template wasn’t already creating a <link rel="canonical" href="{my-hugo-site-page-path}"> in the header of each html content page.

image

I am looking to add a canonical to my PR (Etcd and Kubernetes Post added by hrittikhere · Pull Request #474 · etcd-io/website · GitHub) without altering the global settings which is on the etcd.io repository but I don’t find any similarity here.

This is how I do it:

  1. Copy your theme’s layouts/_default/baseof.html file into your own layouts/_default folder (most themes doesn’t touch baseof.html and use a different partial, so just follow the trail).

  2. Add this:

    {{ with .Params.relcanonical }}
      <link rel="canonical" href="{{ . | relLangURL }}" itemprop="url" />
    {{ else -}}
      <link rel="canonical" href="{{ .Permalink }}" itemprop="url" />
    {{ end -}}
    
  3. In your post frontmatter you can then add:

    relcanonical = "https://example.com/post/"
    

This is assuming that your theme did not provide its own rel=canonical. If it is already generating its own rel=canonical, you need to find it and remove it because search engines (especially goog) will ignore all rel=canonical if there is more than one per page.

Hope it helps.

2 Likes