11ty conditional canonical

SimonCox February 13, 2023
Source
GSC was flagging some Canonical issue on this site so I decided to add the canonical using the page.url parameter in my base.njk nunjucks include. {% raw %}{% endraw %} However, I have already included a Canonical in the frontmatter of some of my posts and there may be reasons why i'd want the canonical to be on a different url. So I added a conditional to state that if the frontmatter for canonical exists then use it else fall back to the standard page url version. And that gave me this: {% raw %}{% if canonical %}{% else %}{% endif %}{% endraw %} Simple but effective. ^ to MrQuest for the tip showing me how to display raw njk code!

Discussion in the ATmosphere

Loading comments...