---
title: 'Only use canonical tag when page is set to index'
url: 'https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586'
markdown: 'https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586.md'
date: '2026-06-21'
description: "Hi everyone, I'm looking for a solution that shows the canonical meta tag only when a page is set to 'index' in the meta tag robots. Just to clarify things: I"
---

[General](https://getgrav.org/forum/general)

#   Only use canonical tag when page is set to index 

 Solved by Thorsten [View solution](https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586#post-38532)

  Started by Thorsten 3 years ago · 8 replies · 904 views    

 [3 years ago](https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586#post-38483 "Permalink") 

Hi everyone,

I'm looking for a solution that shows the canonical meta tag only when a page is set to 'index' in the meta tag robots.

Just to clarify things: I use 'robots' = 'index' or 'noindex' on every page as a meta tag to instruct search engines. However since it's SEO best practice, I only want to show the canonical meta tag when a 'robots' meta tag is available on the page **AND** contains the value 'index'.

Can anyone help me? Any help is much appreciated.

Currently I'm using:

```twig
 <link rel="canonical" href="{{ page.header.routes.canonical ? page.routeCanonical : page.url(true, true ) }}" />
```

to generate the canonical tag.

Best,
Thorsten

last edited 03/17/24 by Thorsten

 [3 years ago](https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586#post-38484 "Permalink") 

@Thorst3n, Please format your post correctly. Code snippets are not shown without proper use of backticks or triple backticks.

Also please explain what you are trying to achieve.

 [3 years ago](https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586#post-38487 "Permalink") 

Hi pamtbaau,

Many thanks for your feedback. I didn't check my post, as I was in a rush. Sorry for that!!!

I worked on the initial post again to clarify my problem and make it easier to understand. I hope this helps.

Best

 [3 years ago](https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586#post-38491 "Permalink") 

Hi

> I use ‘robots’ = ‘index’ or ‘noindex’

you did not specify how you doing this (I will use select field in blueprint with 4 options index, follow / index, nofollow / noindex, follow / noindex, nofollow ) and set something like:

```twig
{% if header.index == indexfollow %}<link rel="canonical" href="{{ page.url(true) }}">{% endif %}
```

hope this will help

 1 reply 

- [ Thorstenah and one more thing. How do I check what value "header.index" currently has? ](https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586#post-38511)

 [3 years ago](https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586#post-38492 "Permalink") 

my mistake - you said that U use meta tag... but U should easily fit my code with your settings

 [3 years ago](https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586#post-38510 "Permalink") 

Hi domena.online,

Many thanks for your help. This makes total sense. But since I'm new to Grav (which seems to be the reason...) I can't get a blueprint to work... It drives me nuts. I use the template resume:
<https://github.com/getgrav/grav-theme-resume>

On top of that I have a multi language page, so my user/pages folder looks like this:

- left (folder)
    resume.de.md
    resume.en.md
    *personal statement (folder)*
    default.de.md
    default.en.md
    *languages (folder)*
    languages.de.md
    languages.en.md
- right
    default.de.md
    default.en.md
    *experience (folder)*
    default.de.md
    default.en.md
    *recognitions (folder)*
    default.de.md
    default.en.md
- root.de.md
- root.en.md

In the users/themes/resume/blueprints folder I have a resume.de.yaml file but it won't change anything in the backend (at least I can't find any changes). I even copied the first example code from here, just to make sure that it would work:
<https://learn.getgrav.org/17/forms/blueprints/example-page-blueprint>

PS: I also created a left folder in the blueprints folder and added a resume.de.yaml file in there but that wouldn't change anything either.
PS 2: The left folder is the homepage if you will.

Do you think you could help me here once more?

Best,
Thorsten

 [3 years ago](https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586#post-38511 "Permalink") [ domena.online Hi I use ‘robots’ = ‘index’ or ‘noindex’ you did not specify how you doing this (I will us… ](https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586#post-38491 "In reply to domena.online") 

ah and one more thing. How do I check what value "header.index" currently has?

 [3 years ago](https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586#post-38513 "Permalink") 

@Thorst3n,

> I have a resume.de.yaml file but it won’t change anything \[..\]

Don't use language extensions like *.*de.yaml *to blueprints.
The field's label and help properties will automatically be translated when using a proper* language.yaml\* file.

> I use ‘robots’ = ‘index’ or ‘noindex’ on every page as a meta tag

Do you mean the following inside the header (aka. frontmatter) of the page?

```yaml
metadata:
  robots: index
```

If so, I also presume you are using field 'Metadata' in Admin on tab 'Options'. In that case, there is no need for a blueprint.

Considering my presumptions the following should work:

- Create a [child theme](https://learn.getgrav.org/17/themes/customization#inheriting-using-the-cli) based on Resume
- Override Resume's template *templates/partials/base.html.twig* by following the instructions in [ Extend base template of inherited theme](https://learn.getgrav.org/17/cookbook/twig-recipes#extend-base-template-of-inherited-theme).
    Replace the onTwigLoader function with: ```php
    public function onTwigLoader() {
    $resume_path = Grav::instance()['locator']->findResource('themes://resume');
    $this->grav['twig']->addPath($resume_path . DIRECTORY_SEPARATOR . 'templates', 'resume');
    }
    ```
- Add the following inside *themes/myresume/templates/partials/base.html.twig*

    ```twig
    {% extends '@resume/partials/base.html.twig' %}

    {% block head %}   
    {{ parent() }}

    {% if page.header.metadata.robots == 'index' %}
        <link rel="canonical" href="{{ page.header.routes.canonical ? page.routeCanonical : page.url(true, true ) }}" />
    {% endif %}
    {% endblock %}
    ```

 [3 years ago](https://getgrav.org/forum/general/only-use-canonical-tag-when-page-is-set-to-index-t7586#post-38532 "Permalink")  Solution 

Hi guys,

Sorry for answering so late, I wasn't working on my page for the last couple of days. However, I got it finaly fixed.

I had to use:

```twig
{% if site.metadata.robots == 'index' and page.header.metadata.robots != 'noindex' %}
  <link rel="canonical" href="{{ page.url(true) }}" />
  {% include 'partials/langswitcher.hreflang.html.twig' %}
{% endif %}
```

This is, because I was always looking for a "general" solution for my website.

The main issue was that I'm new to Grav and twig and had to think every through. But your solutions really helped. 🙂

Many thanks!

 👍 1 

last edited 03/24/24 by pamtbaau

[Log in](https://getgrav.org/login?return=%2Fforum%2Fgeneral%2Fonly-use-canonical-tag-when-page-is-set-to-index-t7586) to reply.

###  Suggested topics

 | Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| [Unified Login system - you might need to reset your password](https://getgrav.org/forum/general/unified-login-system-you-might-need-to-reset-your-password-t9463)    [General](https://getgrav.org/forum/general) · by Andy Miller, 1 week ago |  | 0 | 133 | [1 week ago](https://getgrav.org/forum/general/unified-login-system-you-might-need-to-reset-your-password-t9463 "by Andy Miller") |
| [Multi-site health/status monitor for GRAV](https://getgrav.org/forum/general/multi-site-health-status-monitor-for-grav-t9425)    [General](https://getgrav.org/forum/general) · by lynbor, 1 month ago |  | 3 | 452 | [2 weeks ago](https://getgrav.org/forum/general/multi-site-health-status-monitor-for-grav-t9425 "by lynbor") |
| [Laragon + GRAV Update Issue](https://getgrav.org/forum/general/laragon-grav-update-issue-t9436)    [General](https://getgrav.org/forum/general) · by lynbor, 3 weeks ago |  | 7 | 586 | [2 weeks ago](https://getgrav.org/forum/general/laragon-grav-update-issue-t9436 "by lynbor") |
| [My command line script to manage contact messages](https://getgrav.org/forum/general/my-command-line-script-to-manage-contact-messages-t9441)    [General](https://getgrav.org/forum/general) · by Harry, 2 weeks ago |  | 0 | 173 | [2 weeks ago](https://getgrav.org/forum/general/my-command-line-script-to-manage-contact-messages-t9441 "by Harry") |
| [Login Question](https://getgrav.org/forum/general/login-question-t9420)    [General](https://getgrav.org/forum/general) · by Old Man Umby, 1 month ago |  | 2 | 315 | [4 weeks ago](https://getgrav.org/forum/general/login-question-t9420 "by Andy Miller") |
