1

SEOmatic puts a canonical on every page. But some pages I need to be able to add a custom canonical, but not sure how to overide SEOmatic's otherwise there will be two.

1

Like stated in the docs you can overwrite the default template with your own one and implement your logic however you like. So you can check for certain condition if you want to use the default SEOmatic inputs or your custom one. You can create a custom template based on this file meta template and change line 19 from

{% if seomaticMeta.canonicalUrl |length %}
<link rel="canonical" href="{{ seomaticMeta.canonicalUrl }}" />
{% endif %}

to something like

{% if entry.useCustomData is defined and entry.useCustomData == true%}
   <link rel="canonical" href="{{ whatever }}" />
{% else %} 
    {% if seomaticMeta.canonicalUrl |length %}
        <link rel="canonical" href="{{ seomaticMeta.canonicalUrl }}" />
    {% endif %}
{% endif %}
| improve this answer | |
  • Thanks very much for the answer! I've also been able to find more information in the docs about overriding the default data, and have created this in my layout template. {% if entry.canonicalUrl|length > 0 %} {% set seomaticMeta = seomaticMeta | merge({'canonicalUrl': entry.canonicalUrl}) %} {% endif %} {% hook 'seomaticRender' %} – David Ball Jan 5 '18 at 14:27
  • 1
    Yes that is a really good approach as well, glad you found a solution – Robin Schambach Jan 5 '18 at 15:08
2

Robin's answer above is valid, but I have managed to create an override in my main _layout template like this:

{% if entry.canonicalUrl|length > 0 %}
    {% set seomaticMeta = seomaticMeta | merge({'canonicalUrl': entry.canonicalUrl}) %}
{% endif %}

{% hook 'seomaticRender' %}
| improve this answer | |
  • I prefer doing it this way – andrew.welch Jan 7 '18 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.