← All guides

Framework Guide

Next.js OG Images: Five Metadata Traps and How to Fix Them

How Next.js resolves Open Graph and Twitter metadata, five traps that ship the wrong link preview or none, and the fix for each, reproduced on Next.js 16.

How Next.js resolves OG metadata

Most broken link previews on Next.js sites are not missing code. The tags are declared, the image route works, and the page still ships the wrong card or none. The cause is almost always the resolution model, which follows two different rules for two kinds of metadata.

File conventions cascade. An opengraph-image or twitter-image file (.tsx, .png, .jpg) in a segment applies to that segment and to every segment below it. Put app/opengraph-image.tsx at the root and a page that declares nothing about images still gets it:

<!-- /plain, whose page only sets { title: "Plain" } -->
<meta property="og:image" content="https://acme.com/opengraph-image?9abae9a99e718699"/>
<meta name="twitter:image" content="https://acme.com/opengraph-image?9abae9a99e718699"/>

Metadata objects replace. Each segment's metadata export or generateMetadata result is merged into its parent's one top-level key at a time. When a page declares openGraph, its object becomes the resolved openGraph: the layout's openGraph is not merged into it, and neither is the image the root file contributed. The same goes for twitter. There is no deep merge for either key.

Three more details explain the rest of this guide:

  • After every segment has resolved, Next fills in twitter:title, twitter:description and twitter:image from the final openGraph, but only for the fields the resolved twitter object does not already have. An inherited twitter.title counts as having one.
  • A twitter object's card defaults when that object is resolved: summary_large_image if it carries images of its own, summary if it does not. Images filled in later from openGraph do not change the card.
  • A file convention wins over the object in its own segment, unless that object sets images itself. A segment with an opengraph-image file gets that image when it declares openGraph without images, and the object's images when it declares them.

Every trap below is one of these rules doing exactly what it says. The tags quoted in each section are what Next.js 16.4.2 served from a scratch app built to show that trap, read with curl. Each section also names the site audit finding that reports it, so you can tell whether your own site has it.

Trap 1: openGraph on a page drops the inherited image

Symptom

The homepage and most routes unfurl with your card. One route, usually one that sets its own title and description for sharing, unfurls with no image at all, and on X it shows a small text-only card.

The root has app/opengraph-image.tsx. The page has this:

// app/blog/page.tsx
export const metadata: Metadata = {
  title: "Blog",
  openGraph: { title: "Blog", description: "Posts" },
};

What it serves:

<title>Blog | Acme</title>
<meta property="og:title" content="Blog"/>
<meta property="og:description" content="Posts"/>
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Blog"/>
<meta name="twitter:description" content="Posts"/>

No og:image, no twitter:image, and a summary card.

Cause

The page's openGraph object replaced the resolved one, and the root card lived inside the resolved one. The object has no images, so nothing does. The twitter tags are filled from that image-less object afterwards, so the card falls back to summary as well.

Fix

Pick one, by what the route should show.

The parent's card is fine: stop declaring openGraph on the page. The root card comes back. og:title and og:description come from the page's title and description, with the title template applied, but only when no layout above the page sets openGraph.title or openGraph.description. A page that declares no openGraph inherits the layout's object as it is, so with openGraph: { title: "Acme" } in the root layout every such page serves og:title "Acme", and twitter:title follows it. Leave title and description out of the layout's openGraph. The homepage still gets them from the root title and description.

// app/blog/page.tsx
export const metadata: Metadata = {
  title: "Blog",
  description: "Posts",
};

The route should have its own card: add an opengraph-image file to the segment. It applies even though the page declares openGraph, as long as that object has no images key. A page built from the shared helper below has one, so leave images out of the object on that page.

// app/blog/opengraph-image.tsx
import { ImageResponse } from "next/og";

export const size = { width: 1200, height: 630 };
export const contentType = "image/png";

export default function Image() {
  return new ImageResponse(
    <div style={{ display: "flex", width: "100%", height: "100%", fontSize: 96,
                  alignItems: "center", justifyContent: "center",
                  background: "#111", color: "#fff" }}>
      Blog
    </div>,
    size,
  );
}

Every page declares openGraph through a shared helper: restate images in the shared object, so no page can leave it out.

// lib/metadata.ts
import type { Metadata } from "next";

export const sharedOpenGraph = {
  siteName: "Acme",
  type: "website",
  images: ["/opengraph-image"],
} satisfies Metadata["openGraph"];

// app/blog/page.tsx
import type { Metadata } from "next";
import { sharedOpenGraph } from "@/lib/metadata";

export const metadata: Metadata = {
  title: "Blog",
  openGraph: { ...sharedOpenGraph, title: "Blog", description: "Posts" },
};

All three were checked against the served head. The third one serves /opengraph-image without the hash Next appends to a file convention's URL (?9abae9a99e718699), which changes when the file changes, so a platform that cached the old card has less to tell it the image changed. Prefer the first two when they fit.

Detected by

image_missing (critical). On a site detected as App Router, the finding's fix names the segments by URL shape and says the replaced openGraph object is the likely cause when other routes on the site do resolve a card.

Trap 2: a root twitter-image overrides every page on X

We shipped this one on properog.com. Every page had its own Open Graph card, and on X every page showed the homepage's.

Symptom

Facebook, LinkedIn and Slack show each page's own card. X shows the same card for every link to the site. Any checker that reads only og:image says the page is fine, because og:image is fine.

The app has app/opengraph-image.tsx, app/twitter-image.tsx, and an opengraph-image file in each segment that should look different:

<!-- /pricing -->
<meta property="og:image" content="https://acme.com/pricing/opengraph-image?a4d42e764d145972"/>
<meta name="twitter:image" content="https://acme.com/twitter-image?bef783407666cb52"/>

<!-- /blog -->
<meta property="og:image" content="https://acme.com/blog/opengraph-image?2988c2edae5114e8"/>
<meta name="twitter:image" content="https://acme.com/twitter-image?bef783407666cb52"/>

Cause

The root twitter-image file cascades like any file convention, so every descendant inherits a twitter object that already has images. Next only fills twitter:image from openGraph when the twitter object has none, so the per-page card never reaches it. X reads twitter:image in preference to og:image, so on X the root file wins on every route. A root layout declaring twitter: { images: [...] } does the same thing: with that key set, every page served the same twitter:image under its own og:image.

Fix

Delete app/twitter-image.*, or the images key of the root twitter object. With neither, each page's twitter:image is filled from its own openGraph:

<!-- /pricing, after deleting app/twitter-image.tsx -->
<meta property="og:image" content="https://acme.com/pricing/opengraph-image?a4d42e764d145972"/>
<meta name="twitter:image" content="https://acme.com/pricing/opengraph-image?a4d42e764d145972"/>

You almost never need a separate image for X. If one segment really does, put the twitter-image file in that segment, not at the root.

Detected by

twitter_image_stale when one twitter:image sits under pages whose og:image differs, which is this trap exactly. twitter_image_shared when the pages also share their og:image and the twitter:image is a different URL across templates. A page with no twitter:image at all is not reported: X falls back to og:image, and that is the setup this fix leaves you with.

Trap 3: twitter: { title } without card renders a small card

Symptom

The page has a 1200x630 card and twitter:image points at it, yet X shows a small square thumbnail beside the title. The root layout sets card: "summary_large_image", so it looks as if it should not be possible.

// app/blog/page.tsx
export const metadata: Metadata = {
  title: "Blog",
  openGraph: { title: "Blog", description: "Posts" },
  twitter: { title: "Blog" },
};
<meta property="og:image" content="https://acme.com/blog/opengraph-image?f804505811951037"/>
<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Blog"/>
<meta name="twitter:image" content="https://acme.com/blog/opengraph-image?f804505811951037"/>

Cause

The page's twitter object replaced the root's, and the root's card went with it. The new object has no images of its own, so its card defaults to summary. twitter:image is filled from openGraph after that, too late to change the card.

Deleting a card: "summary" line is not the fix, for the same reason: the default is summary too.

Fix

Either declare no twitter key on the page, so the root's card stands and the title, description and image fill from the page's own openGraph:

// app/blog/page.tsx
export const metadata: Metadata = {
  title: "Blog",
  openGraph: { title: "Blog", description: "Posts" },
};

Or restate the card in every twitter object you declare:

twitter: { card: "summary_large_image", title: "Blog" },

Both served twitter:card summary_large_image. If a shared helper builds your metadata, put the card in the helper so no page can forget it.

Detected by

twitter_card_small: a page with an og:image whose twitter:card is anything but summary_large_image. The sample line names the card it found, for example /blog (card=summary).

Trap 4: a root twitter block gives every page the same title on X

Symptom

Every link to the site shows the site's name and tagline on X, whatever page it points at. On Facebook and LinkedIn each page has its own title.

// app/layout.tsx
export const metadata: Metadata = {
  title: { default: "Acme", template: "%s | Acme" },
  openGraph: { title: "Acme", description: "Root description" },
  twitter: {
    card: "summary_large_image",
    title: "Acme",
    description: "The Acme site",
  },
};
<!-- /pricing -->
<meta property="og:title" content="Pricing"/>
<meta name="twitter:title" content="Acme"/>

<!-- /docs -->
<meta property="og:title" content="Docs"/>
<meta name="twitter:title" content="Acme"/>

Cause

Pages that declare openGraph but no twitter inherit the root's twitter object as it is. It already has a title and a description, so Next has nothing to fill from the page's openGraph. The homepage looks right, which is why this trap tends to survive review: the person checking it checks the homepage.

Fix

Keep only what is true of every page in the root twitter object: the card type, and site or creator if you use them. Do the same for the root openGraph, for the reason in Trap 1's first fix: a page that declares no openGraph of its own would otherwise serve the layout's title on every platform. The homepage's title and description come from the root title and description instead.

// app/layout.tsx
export const metadata: Metadata = {
  title: { default: "Acme", template: "%s | Acme" },
  description: "Root description",
  openGraph: { siteName: "Acme", type: "website" },
  twitter: { card: "summary_large_image" },
};
<!-- /pricing, after -->
<meta property="og:title" content="Pricing"/>
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:title" content="Pricing"/>

The page's own openGraph title and description now reach X. Watch for the same shape one level down: a section layout with a twitter.title gives every page in that section one title.

Detected by

twitter_title_generic: one twitter:title repeated across pages whose og:title differs. It can only be seen across pages, which is why a single-URL check cannot find it and a site audit can.

Trap 5: the Pages Router ignores a metadata export

Symptom

A page in pages/ exports a metadata object, the build passes, and the page ships none of it.

// pages/index.tsx
export const metadata = {
  title: "Home",
  openGraph: { title: "Home", images: ["https://acme.com/home-card.png"] },
};

export default function Home() {
  return <main>home</main>;
}

Served, with the defaults from _app shown below: no title, no og:title, and none of the export's image.

<meta property="og:image" content="https://acme.com/og.png"/>
<meta name="twitter:card" content="summary_large_image"/>

Cause

The Metadata API is an App Router feature. In pages/, an exported metadata object is just an unused export: nothing reads it, and nothing warns. Nothing cascades in the Pages Router either. There are no segments and no file conventions, so a tag reaches the page only if something in its render tree puts it in next/head.

Fix

Render the tags with next/head on each page. A site-wide default goes in _app, and the key prop is what lets a page replace it:

// pages/_app.tsx
import Head from "next/head";
import type { AppProps } from "next/app";

export default function App({ Component, pageProps }: AppProps) {
  return (
    <>
      <Head>
        <meta property="og:image" content="https://acme.com/og.png" key="og:image" />
        <meta name="twitter:card" content="summary_large_image" key="twitter:card" />
      </Head>
      <Component {...pageProps} />
    </>
  );
}

// pages/team.tsx
import Head from "next/head";

export default function Team() {
  return (
    <>
      <Head>
        <title>Team | Acme</title>
        <meta property="og:title" content="Team" />
        <meta property="og:image" content="https://acme.com/team.png" key="og:image" />
      </Head>
      <main>team</main>
    </>
  );
}

With matching keys the page serves one og:image, its own. Without the key on the page's tag, it served both:

<meta property="og:image" content="https://acme.com/og.png"/>
<meta name="twitter:card" content="summary_large_image"/>
<title>Team | Acme</title>
<meta property="og:title" content="Team"/>
<meta property="og:image" content="https://acme.com/team.png"/>

Which of two og:image tags a platform uses is up to the platform. Our audit reads the first one, which here is the default, not the page's card.

Detected by

image_missing, for a page whose head has no og:image. The audit tells the routers apart from the served page (App Router responses vary on rsc; Pages Router pages carry __NEXT_DATA__ and /_next/static/chunks/pages/). On a Pages Router site, image_missing says that each page's next/head has to emit the tag itself, and the code it hands you is plain meta tags rather than a metadata export that would compile and change nothing.

Verify your fix

Read the served head as a crawler does. Since Next.js 15.2, metadata from an async generateMetadata on a dynamic route is streamed: browsers, and curl with its default user agent, get the tags after </head>, while user agents Next recognises as bots (Facebook, X, Slack and LinkedIn all were) get them in the head. Send a crawler's user agent so you see what they see:

curl -sA 'facebookexternalhit/1.1' https://your-site.com/blog \
  | grep -oE '<meta (property|name)="(og|twitter):[^"]*" content="[^"]*"'

Run it on one page of each template, not just the homepage. Every trap above leaves the homepage looking correct.

Audit the whole site. The site audit reads your sitemap, groups URLs into page templates, samples across them, and reports the findings named in this guide with a fix for each. Traps 2 and 4 can only be seen by comparing pages, so this is the check that catches them. It follows a 12-page crawl from the entry page as well, so routes your sitemap forgot are sampled too.

Check one URL. The checker scores a single page's card (dimensions, file size, tags) and shows how it renders on each platform. Use it on the route you just fixed. For an example, check this guide's own card.

Then refresh the platforms' caches. Facebook and LinkedIn keep the card they scraped. Facebook's Sharing Debugger and LinkedIn's Post Inspector fetch the page again on request. A file convention's URL carries a hash that changes when the file changes, so editing the card file also gives it a new image URL, which helps any platform that caches by image URL. A card whose file is unchanged but whose data is (a title read from a database) keeps its URL.

Frequently Asked Questions

Does opengraph-image cascade to child routes in Next.js?

Yes. An opengraph-image file applies to its segment and every segment below it. What stops it is a child segment declaring openGraph in its metadata without images: that object replaces the resolved openGraph, and the inherited image goes with it. A child segment's own opengraph-image file still applies in that case.

Do I need twitter:image if I already have og:image?

No. When the resolved twitter object has no images, Next fills twitter:image from the page's openGraph images, and X falls back to og:image anyway. Declaring one at the root, with a twitter-image file or twitter.images, is what causes trouble: it overrides every page's own card on X.

Why does X show a small card when my image is 1200x630?

Because twitter:card is summary. A page that declares a twitter object replaces the root's, card included, and Next defaults the card to summary when that object has no images of its own. Restate card: "summary_large_image" in every twitter object you declare, or declare no twitter key on the page.

Can I use the metadata export in the Next.js Pages Router?

No. The Metadata API only runs in the App Router. In pages/ the export builds without a warning and renders nothing. Use next/head on each page, put site-wide defaults in _app, and give each default tag a key so a page's own tag with the same key replaces it instead of shipping beside it.

Why doesn't curl show my og:image in the head?

Next.js streams metadata from an async generateMetadata to user agents it does not recognise as bots, so curl's default user agent gets the tags in the body. Send a crawler's user agent, for example curl -A 'facebookexternalhit/1.1', to see the head that Facebook, X, Slack and LinkedIn receive.

Audit your site

Sample pages across every template in your sitemap and see which ones ship the wrong card, or none. Free, no account needed.

Related guides