next-seo icon indicating copy to clipboard operation
next-seo copied to clipboard

additionalMetaTags cannot render multiple meta tags with same property name

Open MarkoCen opened this issue 3 years ago • 6 comments

Hi, I try to use additionalMetaTags to add open graph locale alternative meta tags

additionalMetaTags={[
  { property: 'og:locale:alternative', content: 'ja'},
  { property: 'og:locale:alternative', content: 'ge'}
]}

What I expect the rendered html should include two meta tags

<meta property="og:locale:alternative" content="ja" />
<meta property="og:locale:alternative" content="ge" />

But seem like it only pick the last meta tag with same property name

<meta property="og:locale:alternative" content="ge" />

If the behavior is on purpose, then what is the proper way to add multiple meta tags with same property name? Thanks.

Versions: "next": "10.0.6", "next-seo": "4.19.0", "react": "^17.0.1", "react-dom": "^17.0.1"

MarkoCen avatar Feb 04 '21 02:02 MarkoCen

You could see the issue in this repl.it project https://repl.it/join/wkppmvcy-markocen

MarkoCen avatar Feb 04 '21 02:02 MarkoCen

🤔 This is due to next-seo sets the key and Next only renders unique keys. If you have a look at the docs here it mentions it: https://github.com/garmeeh/next-seo#additional-meta-tags

To fix it, If you look at this line https://github.com/garmeeh/next-seo/blob/master/src/meta/buildTags.tsx#L656

We would need to allow an optional key prop to be passed in.

garmeeh avatar Feb 20 '21 17:02 garmeeh

This would be extremely helpful. In particular, the tag used in the example, dc:creator, ought to be listed multiple times if there are multiple authors as specified by Dublin Core.

ja573 avatar Aug 10 '21 11:08 ja573

thinking This is due to next-seo sets the key and Next only renders unique keys. If you have a look at the docs here it mentions it: https://github.com/garmeeh/next-seo#additional-meta-tags

To fix it, If you look at this line https://github.com/garmeeh/next-seo/blob/master/src/meta/buildTags.tsx#L656

We would need to allow an optional key prop to be passed in.

Couldn't you, for example, concatenate the current key with the content of the tag in https://github.com/garmeeh/next-seo/blob/420eb12ff7c6d2e15412d3bd09a0dca27863084f/src/meta/buildTags.tsx#L676 or use the index of the element?

ja573 avatar Aug 10 '21 11:08 ja573

Is this at all included in the roadmap, @garmeeh ?

ja573 avatar May 30 '22 10:05 ja573

It looks like there's a keyOverride property you can now pass in to meta tags to override the key to tell React that they're different. See issue #666 and PR #672.

ediblecode avatar Nov 03 '22 11:11 ediblecode