How to assign meta data for taxonomy output pages (for categories and tags pages) Using the SEO plugin v2.3.4?

Hello friends, another problem befalls me on the way to publishing and finalizing my blog.
The problem is that I can not specify my metadata on the taxonomy pages.
I need to add meta descriptions for category pages and tags:

  1. title
  2. description
  3. image (facebook + twitter)
    The site has the following plugin installed:

But how can I specify the mate data for taxonomies not where not indicated.

I will be very grateful for any help.

Is it not possible at all? Friends I’m sure there must be some solution. I will be very grateful for any help.

Two disclaimers…

  • I don’t know the plugin ‘grav-plugin-seo’.
    You might consider going to the source and file an issue.
  • I’v never looked at the Open Graph Protocol. The only thing I know about it is what I have read just now…

Nonetheless, I can share some thinking…

  • In template ‘base.html.twig’ you can test if the page uses a blog template using:
    {% if page.template == 'blog' %}
    
  • You can also test if there is a parameter defined:
    {% if uri.params is defined %}
    
  • You can get the parameters using:
    # uri.params could look like '/tag:photography/page:2'
    {% set params = explode('/', substr(uri.params, 1)) %}
    
  • Get individual parameter by:
    {% set taxon = explode(':', params[0]) %}
    

A meta element could then be generated in 'base.html.twig 'as follows:

{% if page.template == 'blog' and uri.params is defined %}
    {% set params = explode('/', substr(uri.params, 1)) %}

    {% for param in params %}
        {% set taxon = explode(':', param) %}

        {% if taxon[0] == 'category' %}
            <meta property="article:section" content="{{ taxon[1] }}">
        {% elseif taxon[0] == 'tag' %}
            <meta property="article:tag" content="{{ taxon[1] }}">
        {% endif %}
    {% endfor %}
{% endif %}

You could copy the above code snippet in ‘base.htmt.twig’ right below {% include 'partials/metadata.html.twig' %}

Hope this helps…

1 Like

Have you been able to find a suitable solution to your question?

Yes, I did. You are absolutely right in all of your comments. And I am very grateful for your attention and time given to me. The thing is that I did not immediately understand where and how to override the file page_header.html.twig which was actually in the gantry 5 plugin folder. As a result, I did everything but with switch. I am very grateful to you, mark your decision as correct as only thanks to you I managed to understand, well, I wrote my decision on the basis of yours. Thanks again.

PS. Just want to note that the solution for describing the categories that is indicated here:

I did not work, although I tried all possible options.

I will describe in more detail how I did it:
In order that we could independently manage the output of metadata on a site running Gantry 5 plug-in, we need to reassign the metadata output file itself for this to begin with, I copied the file:
* user / public_html / user / plugins / gantry5 / engines / nucleus / templates / partials / page_head.html.twig

to the folder:
* user / data / gantry5 / themes / g5_helium / partials / page_head.html.twig

After that, everything that I will be added to the file that is in the custom folder will be displayed instead of the stock output (that is, the output location from the page_head.html.twig file that is in the plugin folder).

Next, I created the __SDStudio__CATEGORY_DESC.html.twig file:
* user / public_html / user / data / gantry5 / themes / g5_helium / particles / __ SDStudio__CATEGORY_DESC.html.twig

And already in it has placed the code for SWITCH, an example of a code:
{# SWITCH CASE - Description of categories START #}
{% set CategoryDescription = ‘’%}

{% switch grav.uri.param ('category')%}
    {% case "WordPress"%}
        {% set CategoryDescription = 'WordPress merciless'%}
    {% case "Grav"%}
        {% set CategoryDescription = 'Grav is a file-based CMS (flat-file CMS)'%}
     {% default%}
        {% set CategoryDescription = ''%}
{% endswitch%}
{# SIMPLE OUTPUT OF VARIABLES CategoryDescription #}
{{CategoryDescription}}
{# SWITCH CASE - Category description END #}

Next, I display the contents of a variable anywhere on the site using:
{% include '@particles / __ SDStudio__CATEGORY_DESC.html.twig'%}

1 Like

Hi @dydaevskiy

Author of the seo plugin here,

This is indeed a case which is in my opinion a bit out of the scope of this plugin and is probably better handled with twig only.

Feel free to suggest it on the plugin repo, and we will see if it gather some interest or if someone has an idea about how to implement it.

Paul