Creating custom meta tag

Created on 18 November 2024, 7 months ago

Problem/Motivation

I would like to create some custom meta tags for DataCite. I went to the Add Custom tag page @ /admin/config/search/metatag/custom-tags/add but not sure which drop-down option to choose for the 3 fields (HTML element, Name attribute, Value attribute). For example,

  1. what do "Meta" and "Link" mean for the HTML field?
  2. what is the difference between "Name", "Property" and "Item Prop" for the Name attribute field and what do "Http equiv" and "Rel" mean?
  3. what do the "Content" and "Href" choice mean for the Value attribute field?
  4. how do i specify which content field to use for the value?
  5. if a field i want to map to allows multiple input, how to configure that?

Proposed resolution

Perhaps add info about the custom tag configuration to the documentation page β†’

πŸ’¬ Support request
Status

Active

Version

2.1

Component

Documentation

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @monaw
  • Here's a blog post https://www.morpht.com/blog/unleashing-power-metatag-custom-tags which would help you.
    I'll write a drupal org handbook page for custom tags

  • thank you @naveenvalecha!

  • πŸ‡§πŸ‡ͺBelgium gillesbailleux La Roche-en-Ardenne

    Greetings,

    @naveenvalecha's blog post begins with an example of a custom meta tag:
    <link rel="alternate" type="application/rss+xml" href="https://example.com/rss.xml">

    The blog post continues with a custom meta tag added through the metatag_custom_tags module:
    <meta name="sitename" content="Custom Meta Tag - Demo Site">

    To my understanding, the metatag_custom_tags module currently allows two attributes and not three as mentioned in the first example.

    Here is the custom meta tag I would like to create:
    <link rel="icon" type="image/svg+xml" href="/favicon.svg" />

    Here are the informations implemented in /admin/config/search/metatag/custom-tags/icon:

    • Name: icon
    • Description: SVG favicon
    • HTML element: Link
    • Attribute name: Rel
    • Value attribute: Href



    Adding the value /favicon.svg in the custom tags field, this generates the following custom tag:
    <meta rel="icon" href="/favicon.svg" />

    How do I add the type="image/svg+xml" attribute in the custom tags field? Not with a comma because this generates two custom tags. Neither with a pipe: I tried numerous possibilities and none worked.

    Please tell me how to add the type="image/svg+xml" attribute. Thank you.

  • @gillesbailleux
    The Custom Meta tags is designed to support the single html attribute.
    I have updated the blog post to reflect that https://www.morpht.com/blog/unleashing-power-metatag-custom-tags
    I have also updated the issue title and description and converted it to a feature request to seek @damienmckenna thoughts and approval on it before doing the code changes.

  • πŸ‡§πŸ‡ͺBelgium gillesbailleux La Roche-en-Ardenne

    Thank you @naveenvalecha

  • πŸ‡ΊπŸ‡ΈUnited States damienmckenna NH, USA

    This would be a great feature improvement for 2.2.x

  • Pipeline finished with Success
    4 months ago
    Total: 301s
    #419330
  • Pipeline finished with Success
    4 months ago
    Total: 901s
    #419739
  • πŸ‡«πŸ‡·France musa.thomas France πŸ‡«πŸ‡·

    hello there i come from this issue https://www.drupal.org/project/metatag/issues/3498656 πŸ› Custom Meta tags: Allow - in the machine name of the tag Active but it seems not to be integrate here. Also we need to insert colon inside the tag name (the regex become 'replace_pattern' => '[^a-z0-9_-:]+',)

  • @musa.thomas Thanks for your comment. Would you care to provide which metatag are you trying to create i.e. output
    Example

    <meta name="nid" content="13" />
    
  • Status changed to Needs review about 1 month ago
  • πŸ‡ΊπŸ‡ΈUnited States damienmckenna NH, USA
  • πŸ‡ΊπŸ‡ΈUnited States damienmckenna NH, USA

    Thank you for working on this, it will be a great improvement once it's finished.

    Testing this locally I see some issues:

    • The existing standard process of the custom tag's machine name being used as the "name" attribute is removed, so this will break backwards compatibility.
    • It doesn't indicate that the new attributes are required, otherwise no "name" attribute will be output.
    • It doesn't indicate that the name and value fields should be required, otherwise they will be excluded from the output.
    • No indication is given that the extra attributes cannot be edited through the defaults or per-entity forms, they're fixed values for all uses of that custom tag.

    So it still needs a little work but is almost there.

  • πŸ‡ΊπŸ‡ΈUnited States Maeglin

    The existing practice of making a custom tag's name attribute the same as the machine name is also a limitation. No colon characters allowed, for example. Maybe the machine name could be the default if a tag name isn't specified in the definition?

  • πŸ‡ΊπŸ‡ΈUnited States damienmckenna NH, USA

    Note: I missed that there is an update script that adds an initial attribute for each custom tag already in the system, apologies for my oversight and thank you for taking care of that already.

    The other issues still remain though.

Production build 0.71.5 2024