Chapter 1

Getting Started

Add Open Graph meta tags to your Next.js app

Create a connection

  1. Sign in to OpenGraph+
  2. Go to your website’s Meta Tags page
  3. On your first visit you’ll see the Terms of Service; click Agree & Create Connection, then copy your connection URL

Your connection URL looks like https://$OGPLUS_KEY.ogplus.net.

Find your layout

App Router: app/layout.tsx is the root layout. All pages inherit its metadata.

Pages Router: pages/_app.tsx wraps every page.

Add Open Graph meta tags

Set site-wide defaults in your root layout, then set the og:image per page. Next.js doesn’t expose the request path to a layout’s generateMetadata, so each page supplies its own path. These tags control how your pages appear when shared on Twitter, Slack, LinkedIn, and other platforms.

// app/layout.tsx
import type { Metadata } from 'next'

export const metadata: Metadata = {
  openGraph: {
    title: 'My Site',
    description: 'Welcome to my site',
    siteName: 'My Site',
    type: 'website',
    images: ['https://$OGPLUS_KEY.ogplus.net/'],
  },
  twitter: {
    card: 'summary_large_image',
  },
}

Replace https://$OGPLUS_KEY.ogplus.net with your connection URL, and "My Site" with your actual site name. The layout’s image covers the home page; the sections below give every other page an image matching its own path.

What each tag does

Tag Purpose
og:title The title shown in the link preview
og:description The description shown below the title
og:url The canonical URL of the page
og:site_name Your website’s name
og:type Content type (website, article, product)
og:image The social card image (powered by OpenGraph+)
twitter:card Tells Twitter to show a large image card

Dynamic tags for pages

Page-level generateMetadata overrides the layout defaults. Use this to set tags from your data.

Blog posts

// app/posts/[slug]/page.tsx
import { getPost } from '@/lib/posts'

export async function generateMetadata({ params }) {
  const post = await getPost(params.slug)

  return {
    openGraph: {
      title: post.title,
      description: post.excerpt,
      type: 'article',
      images: [`https://$OGPLUS_KEY.ogplus.net/posts/${params.slug}`],
    },
    twitter: {
      card: 'summary_large_image',
    },
  }
}

Products

// app/products/[id]/page.tsx
import { getProduct } from '@/lib/products'

export async function generateMetadata({ params }) {
  const product = await getProduct(params.id)

  return {
    openGraph: {
      title: product.name,
      description: `${product.price} - ${product.description}`,
      type: 'product',
      images: [`https://$OGPLUS_KEY.ogplus.net/products/${params.id}`],
    },
    twitter: {
      card: 'summary_large_image',
    },
  }
}

Static metadata for simple pages

For pages with known paths, use the static metadata export:

// app/about/page.tsx
import type { Metadata } from 'next'

export const metadata: Metadata = {
  openGraph: {
    title: 'About Us',
    description: 'Learn more about our company',
    images: ['https://$OGPLUS_KEY.ogplus.net/about'],
  },
  twitter: {
    card: 'summary_large_image',
  },
}

Pages Router (legacy)

If you’re using the Pages Router, add meta tags via next/head:

// pages/_app.tsx
import Head from 'next/head'
import { useRouter } from 'next/router'

export default function App({ Component, pageProps }) {
  const router = useRouter()

  return (
    <>
      <Head>
        <meta property="og:title" content="My Site" />
        <meta property="og:description" content="Welcome to my site" />
        <meta property="og:url" content={`https://mysite.com${router.asPath}`} />
        <meta property="og:site_name" content="My Site" />
        <meta property="og:type" content="website" />
        <meta property="og:image" content={`https://$OGPLUS_KEY.ogplus.net${router.asPath}`} />
        <meta name="twitter:card" content="summary_large_image" />
      </Head>
      <Component {...pageProps} />
    </>
  )
}

Override tags in individual pages by adding another <Head> block with page-specific values.

Verify

Start your development server and view the page source. Check that all og: meta tags are present with the correct values.

Open the preview tool and paste a URL from your site to see the social card image.

Multiple domains

Running staging and production, subdomains, or several sites under one account? See Multiple domains & environments. For a single site, the connection tag above is all you need.

Automatic Open Graph for your Next.js app

Set up automatic Open Graph tags in under 10 minutes.

Agents welcomeSet up OpenGraph+ on this site. Fetch https://opengraphplus.com/connect.txt and follow it.