How To Setup a Canonical URL With Jekyll?

I have my site setup, and I am getting ready to make a lot of changes to it, but I need the layout and SEO finished first. After running Lighthouse by Google, I noticed all my SEO tips were good, minus that the Canonical link was pointing to my VPS and not to my site url. After some quick google search, I found out that I could just edit in a for the Canonical:

The Github discussion on the topic

So I did this to my default.html:
https://pastebin.com/XQjrsmAF

All fine and dandy right? No. As now there are two canonical URLs, one pointing to my website, and the other to my VPS…

I tried next to use the Jekyll SEO Tag and using the:
canonical_url: 'example .com'

This would be placed in your layout, I’d presume:

layout: default
canonical_url: ‘example .com’

<HTML Stuff Here>

Only thing is, that not only does it just add 2 canonical URLs, they’re both the same, just the Jekyll SEO Tag version adds the port number…

I am stumped, and I need some help, any ideas?

To my knowledge the way Jekyll SEO Tag works is it will prepend your page.url with the domain and baseurl (if used) based on the values in your _config.yml

These would be:

url: "http://yourdomain.com"
baseurl: "/some-subfolder" # typically not used unless you host your site in subfolder

The custom canonical_url variable it mentions is for a specific page. You’d put this in it’s YAML Front Matter if you need to override it’s value.

An example of when you’d do this is if you are cross posting a blog post on your site from another source, and want to use that site’s URL instead to send some link juice to that page.

title: My Cross Posted Article
canonical_url: 'https://someotherdomain.com/original-article-url'
1 Like

Thank you for your reply,

So I have done this:

url: "https://example.com"
baseurl: "/" 

Although, I still get my VPS address as the canonical link.

I also tried to remove the s from https, if that had any bearing:

url: "http://example.com"
baseurl: "/" 

It did not have any bearing, and I still have the canonical link as the IP rather than the actual URL