Add jekyll-seo-tag to your _config.yml file.
jekyll-seo-tag
_config.yml
plugins: - jekyll-seo-tag
Then in the frontmatter for your posts, add the canonical URL:
--- title: How to add a canonical URL to Jekyll posts canonical_url: 'https://your-canonical-url-here' ---