next-seo
next-seo copied to clipboard
additionalMetaTags cannot render multiple meta tags with same property name
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"
You could see the issue in this repl.it project https://repl.it/join/wkppmvcy-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.
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.
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?
Is this at all included in the roadmap, @garmeeh ?
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.