Open Graph Tags
10-20 minBeginner
Implement Open Graph meta tags to control how your content appears when shared on social media.
Prerequisites
- Next.js App Router
Beginner Recommended
Metadata API
Using generateMetadata.
1
Configuring Open Graph
1
Add the openGraph key to your metadata object export.
2
If your page is dynamic, use generateMetadata to fetch data first.
Example
export const metadata = {
openGraph: {
title: 'Acme Corp',
description: 'The best widgets.',
url: 'https://acme.com',
siteName: 'Acme',
images: [
{
url: 'https://acme.com/og.png',
width: 800,
height: 600,
},
],
locale: 'en_US',
type: 'website',
},
}2
Dynamic OG Images
1
Use opengraph-image.tsx (Image Response) to generate images dynamically via code.
2
Place this file in your route segment.
Verification Checklist
- Use the Facebook Sharing Debugger to preview your OG tags.
- Inspect the
<head>of your page to verifyog:title,og:description, andog:imagetags.