React framework
Add automatic MyOG.social images to Next.js App Router metadata with generateMetadata and openGraph images.
Next.js App Router renders metadata through the Metadata API. That is the right integration point for MyOG because HTML-limited crawlers need head tags in the response.
Use generateMetadata for routes whose URL depends on params. Use a shared helper so every blog post, product, or docs page builds the MyOG image URL consistently.
This is a code integration, not a plugin candidate. Developers will want a clear helper they can paste and adapt.
MyOG detects page content and branding automatically. The layout only controls image composition.
Use this pattern in app/blog/[slug]/page.tsx or any dynamic route.
import type { Metadata } from "next"
const siteURL = "https://example.com"
function getMyOGImageURL(pathname: string) {
const pageURL = siteURL + pathname
return `https://api.myog.social/og?url=${encodeURIComponent(pageURL)}&template=screenshot-right`
}
export async function generateMetadata({
params,
}: {
params: Promise<{ slug: string }>
}): Promise<Metadata> {
const { slug } = await params
const pathname = `/blog/${slug}`
const imageURL = getMyOGImageURL(pathname)
return {
alternates: { canonical: pathname },
openGraph: {
url: pathname,
images: [{ url: imageURL, width: 1200, height: 630 }],
},
twitter: {
card: "summary_large_image",
images: [imageURL],
},
}
}Avoid mixing a route-level opengraph-image file with a generateMetadata image unless you mean to provide multiple images. Keep MyOG as the primary image in openGraph.images for pages it should control.
Use params inside generateMetadata. Build the canonical page URL from the slug, then pass that absolute URL into MyOG's url parameter.
Start with the MyOG Open Graph Checker, then refresh social platform caches if needed.
Sign up for free and add generated OG images to every Next.js route.
Already have an account?
cdf733b534ea2f2ed964d150330b323c44837e4f