Next.js Discord

Discord Forum

How to create a meta tag with "property" field instead of "name" using generateMetadata function

Answered
French Angora posted this in #help-forum
Open in Discord
Avatar
French AngoraOP
I am trying to create this meta tag: <meta property="lb:id" content="...">

In generateMetadata function I am returning this:

return {
   other: {
     "lb:id": product?.sku,
  }
}


It's creating meta tag with "name" field
<meta name="lb:id" content="...">

How can I create a metatag with property field?
Answered by joulev
you can just render the tag directly in the page
View full answer

11 Replies

Avatar
you can just render the tag directly in the page
Answer
Avatar
IIRC you can do this

export async function generateMetadata({ params }: { params: { id: string } }): Promise<Metadata> {
 
  return {
    title: 'Product Page',
    meta: [
      { property: 'lb:id', content: "..." },
    ],
  };
}
Avatar
Object literal may only specify known properties, and 'meta' does not exist in type 'Metadata'.ts(2353)
i was a bit surprised that this wasn't already the case, but yeah that is not allowed. wish nextjs team allowed this though
Avatar
French AngoraOP
I tried it but it doesn't work
Avatar
Hmm, Yes, it can't be used.

I might be confused with some other properties.
I guess you can use the meta tag only
Avatar
Ist a canary feature ig
Image
its there in stable also
Avatar
generateParams doesn't have other tag, i might create a pr to fix that
Avatar
French AngoraOP
I just added the meta tag directly inside the component and it's working.

return (
  <>
    <meta property="lb:id" content={product?.sku} />
    <PdpSeoData productSchema={productSchema} product={product} />
    <RenderBuilderContent content={content} model="pdp-template" />;
  </>
);