投稿日:2026/7/22
更新日:2026/7/22

NextSeo)まとめimport { NextSeo } from 'next-seo';
<title> や <meta name="description">、OGP(Open Graph)、Twitter カード、canonical、robots などを、コンポーネントの props として書ける。next/head に <meta> タグを手書きする必要があるが、next-seo を使うと 型安全かつ短い記述で済む。npm install next-seo
ページコンポーネント内に <NextSeo /> を置くと、そのページの <head> にメタタグが出力される。
import { NextSeo } from 'next-seo';
const Page = () => (
<>
<NextSeo
title="ページタイトル"
description="ページの説明文。検索結果に表示される。"
canonical="https://www.example.com/page"
/>
<p>ページ本文</p>
</>
);
export default Page;
出力イメージ:
<title>ページタイトル</title>
<meta name="description" content="ページの説明文。検索結果に表示される。" />
<link rel="canonical" href="https://www.example.com/page" />
DefaultSeo)_app.tsx に DefaultSeo を置いて一括定義する。NextSeo は デフォルトを上書き(マージ) する関係になる。// pages/_app.tsx
import { DefaultSeo } from 'next-seo';
export default function App({ Component, pageProps }) {
return (
<>
<DefaultSeo
titleTemplate="%s | サイト名" // 各ページの title が %s に入る
defaultTitle="サイト名" // title 未指定ページ用
description="サイトのデフォルト説明"
openGraph={{
type: 'website',
locale: 'ja_JP',
site_name: 'サイト名',
}}
/>
<Component {...pageProps} />
</>
);
}
next-seo.config.ts に切り出して <DefaultSeo {...SEO} /> と渡すパターンが定番。| prop | 役割 |
|---|---|
title |
<title> タグ |
titleTemplate |
%s を使ったタイトルの雛形(例 %s | サイト名) |
description |
meta description |
canonical |
canonical URL(重複コンテンツ対策) |
noindex / nofollow |
true で robots メタタグに noindex / nofollow を出力 |
openGraph |
OGP(下記参照) |
twitter |
Twitter カード設定 |
additionalMetaTags |
任意の <meta> を追加 |
additionalLinkTags |
任意の <link> を追加(favicon など) |
<NextSeo
title="記事タイトル"
description="記事の説明"
openGraph={{
url: 'https://www.example.com/articles/1',
title: 'OGP用タイトル', // 未指定なら title を流用
description: 'OGP用の説明', // 未指定なら description を流用
images: [
{
url: 'https://www.example.com/og.png',
width: 1200,
height: 630,
alt: 'OG画像の説明',
},
],
siteName: 'サイト名',
}}
twitter={{
handle: '@handle',
site: '@site',
cardType: 'summary_large_image',
}}
/>
<NextSeo noindex nofollow />
next-seo は JSON-LD 用のコンポーネントも提供している。リッチリザルト対策に使う。
import { ArticleJsonLd, BreadcrumbJsonLd } from 'next-seo';
<ArticleJsonLd
url="https://www.example.com/articles/1"
title="記事タイトル"
images={['https://www.example.com/og.png']}
datePublished="2026-07-23T09:00:00+09:00"
authorName="著者名"
description="記事の説明"
/>
ProductJsonLd、FAQPageJsonLd、LocalBusinessJsonLd など多数ある。pages/ ディレクトリ)向けのライブラリ。内部で next/head を使っている。app/ ディレクトリ)では、Next.js 標準の Metadata API(export const metadata / generateMetadata)を使うのが公式推奨。NextSeo は App Router のサーバーコンポーネントでは動かない。// App Router ではこちらを使う
export const metadata = {
title: 'ページタイトル',
description: '説明',
openGraph: { ... },
};
useAppDir={true} を付けて使う)。DefaultSeo と各ページの NextSeo の 二重管理に注意。ページ側で指定した値が優先される。canonical は動的ページで クエリパラメータを除いた正規 URL を指定する。titleTemplate を使うとページ側は title="記事名" だけ書けばよくなり、サイト名の付け忘れ・重複を防げる。images は絶対 URL で指定する(相対パスだと SNS 側で解決できない)。