Opengraph metadata custom property fields
Answered
Polar bear posted this in #help-forum
Polar bearOP
I'm using the Next.js 13 with app directory and I want to add opengraph metadata.
Adding title, description and url is straight forward using the following code:
which creates the following output:
But is there any way to create metatags with the property of product:brand, product:availability and so on?
The expected output is on the attached image below.
Adding title, description and url is straight forward using the following code:
export async function generateMetadata(props: Props): Promise<Metadata> {
return {
openGraph: {
title: "foo",
description: "bar",
url: "buzz",
},
}
}which creates the following output:
<meta property="og:title" content="foo">
<meta property="og:description" content="bar">
<meta property="og:url" content="buzz">But is there any way to create metatags with the property of product:brand, product:availability and so on?
The expected output is on the attached image below.
26 Replies
i haven't looked to see if there is an official method, but you can use custom: https://nextjs.org/docs/app/api-reference/functions/generate-metadata#other
Polar bearOP
It generates the metatag as
But I want to add the custom field in the
<meta name="custom" content="meta" />But I want to add the custom field in the
property entry as:<meta property="custom" content="meta" />like make custom to the key and the meta to the value your setting
so this should work
export const metadata = {
other: {
'product:brand': 'Facebook',
},
}wait, i missunderstood your issue
Polar bearOP
yeah it generates as
But I want
<meta name="product:brand" content="Facebook" />But I want
<meta property="product:brand" content="Facebook" />i see the issue, but i don't know the answer ðŸ˜
i would say to use the ldjson as i can't see anything better ðŸ˜
https://developers.facebook.com/docs/marketing-api/catalog/guides/microdata-tags/
<script type="application/ld+json">
{
"@context":"https://schema.org",
"@type":"Product",
"productID":"facebook_tshirt_001",
"name":"Facebook T-Shirt",
"description":"Unisex Facebook T-shirt, Small",
"url":"https://example.org/facebook",
"image":"https://example.org/facebook.jpg",
"brand":"facebook",
"offers": [
{
"@type": "Offer",
"price": "7.99",
"priceCurrency": "USD",
"itemCondition": "https://schema.org/NewCondition",
"availability": "https://schema.org/InStock"
}
],
"additionalProperty": [{
"@type": "PropertyValue",
"propertyID": "item_group_id",
"value": "fb_tshirts"
}]
}
</script>https://developers.facebook.com/docs/marketing-api/catalog/guides/microdata-tags/
note that ldjson for nextjs is sligntly diferent
but idk if that works for you
Polar bearOP
F
Looks like ldjson is the only option
Thanks for the help!
Looks like ldjson is the only option
Thanks for the help!
can i suggest creating an issue on the repo asking for how to achive this tho
Polar bearOP
Yes I should probably do this.
as they might have a secret way of it, or might fix 🙂
@Polar bear I'm using the Next.js 13 with app directory and I want to add opengraph metadata.
Adding title, description and url is straight forward using the following code:
typescript
export async function generateMetadata(props: Props): Promise<Metadata> {
return {
openGraph: {
title: "foo",
description: "bar",
url: "buzz",
},
}
}
which creates the following output:
html
<meta property="og:title" content="foo">
<meta property="og:description" content="bar">
<meta property="og:url" content="buzz">
But is there any way to create metatags with the property of product:brand, product:availability and so on?
The expected output is on the attached image below.
i think it's the same as this question https://nextjs-forum.com/post/1148630247634386954
just simply add the tag to the page
Answer
wait, just in the body... or what is the mythology
yes just in the body
also the issue is that it looks like its a facebook thing that no-one else recognises
facebook recognising it is enough
@joulev yes just in the body
Polar bearOP
This was it!
Thanks for the help!
Thanks for the help!
like i mean that on every list i could find, it wasn't on it, so nextjs probibly might not know about it
@Polar bear This was it!
Thanks for the help!
note that it is not documented so it may break at any moment, add a test case to check for this in your code
because who knows, next nextjs canary might break it
but this has been working for me fine yeah