We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
Jan 15, 2018 6:57 AM
On our blog posts we specify the canonical URL using {{ page_meta.canonical_url }}
However if the editor adds a custom canonical URL that is different (eg. if the blog originally appeared as a guest blog on another site) we end up with TWO canonical tags served.
Not sure how to overcome this - is it possible to add an IF statement to the original canonical line? ie. only show this if the custom canonical hasn’t been defined?
Jan 16, 2018 11:57 AM
@simon you should be able to use a conditional statement like the following to check to see if a custom canonical URL (content.link_rel_canonical_url) exists:
{% if content.link_rel_canonical_url %}
{{ link_rel_canonical_url }}
{% else %}
{{ page_meta.canonical_url }}
{% endif %}
Let me know if this works for you!
All the best,
William
Feb 5, 2018 5:22 AM
@wspiro thanks so much for this. I had to amend slightly so the second line read
{{ content.link_rel_canonical_url }}
but otherwise worked perfectly!
Thanks again
Simon