Guide
Sanity SEO: The Complete Guide for Sanity CMS (2026)
Sanity SEO works differently from WordPress SEO. Sanity is a headless CMS: it stores your content, and your frontend decides what ends up in the HTML. That means every meta tag, sitemap entry and JSON-LD block has to be modelled in Sanity Studio and rendered by your site. This guide covers what you need to set up, in order.
What Sanity does (and doesn't do) for SEO
Out of the box, Sanity gives you structured content, a GROQ API and a CDN. Everything search engines read is your responsibility:
| SEO task | Handled by Sanity? | How to handle it |
|---|---|---|
| Meta title and description | No — you model the fields | Add an SEO object to each document type and render it in your frontend's <head>. |
| Open Graph and X cards | No | Store social title, description and image; fall back to the SEO fields. |
| Canonical URL and robots | No | Store per-document overrides; derive the default canonical from the slug. |
| XML sitemap | No | Generate it in the frontend from a GROQ query over published documents. |
| Hreflang alternates | No | Derive them from document translations (e.g. @sanity/document-internationalization). |
| Structured data (JSON-LD) | No | Model Schema.org types as fields and serialise them to a JSON-LD script. |
| Redirects | No | Store redirect documents and apply them in the frontend or at the edge. |
| Image alt text | Partly | Add an alt field to image types; Sanity AI Assist can draft descriptions. |
1. Model SEO fields in Sanity Studio
Put SEO data in one reusable object type and add it to every indexable document. You can write that object yourself, or install a Sanity SEO plugin that ships it with previews and validation:
import { defineConfig } from 'sanity'
import seofields from 'sanity-plugin-seofields'
export default defineConfig({
// ...projectId, dataset, schema
plugins: [seofields()],
})
// schemas/page.ts
defineField({ name: 'seo', title: 'SEO', type: 'seoFields' })2. Render metadata in your frontend
Fetch the SEO object with the page and turn it into head tags. In the Next.js App Router that happens in generateMetadata; other frameworks are covered in frontend integration.
import type { Metadata } from 'next'
import { buildSeoMeta } from 'sanity-plugin-seofields/next'
export async function generateMetadata({ params }): Promise<Metadata> {
const page = await getPage((await params).slug)
return buildSeoMeta({
seo: page.seo,
baseUrl: 'https://example.com',
path: `/${page.slug}`,
defaults: { title: page.title },
})
}3. Generate a sitemap from GROQ
Query published, indexable documents and return them from app/sitemap.ts. Exclude documents whose robots setting is noindex so the sitemap and the page agree. The sitemap and redirects guide has the full version.
import type { MetadataRoute } from 'next'
import { client } from '@/sanity/client'
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const docs = await client.fetch<{ slug: string; _updatedAt: string }[]>(
`*[_type in ["page", "post"] && defined(slug.current) && seo.robots.noIndex != true]{
"slug": slug.current, _updatedAt
}`,
)
return docs.map((d) => ({
url: `https://example.com/${d.slug}`,
lastModified: d._updatedAt,
}))
}4. Canonicals, robots and hreflang
Default the canonical to the document's own URL and only let editors override it when content is syndicated. Keep preview and draft routes out of the index. For multilingual sites, output reciprocal hreflang tags for every translation — see hreflang in Sanity.
5. Add structured data (JSON-LD)
Structured data helps search engines and AI assistants understand what a page is about — an article, a product, a local business. Model the Schema.org properties as fields so editors can fill them in, then output a JSON-LD script. The Schema.org reference lists 39 types with copyable examples.
6. Prepare for AI search
AI assistants favour pages with clear entities, direct answers and clean structured data. Publish an llms.txt, keep answers near the top of the page, and review the GEO checklist. For dedicated tools, see AI search optimization tools for Sanity.
7. Audit and monitor
Once content is live, check it in two places: inside the Studio (missing descriptions, duplicate titles, weak scores) and in Google Search Console (which documents earn impressions and clicks). The SEO Health Dashboard covers the first, and Performance shows Search Console and GA4 data next to each document.
Sanity SEO checklist
- Every indexable document type has a title, description and social image field — with sensible fallbacks to the document title and main image.
- The frontend renders one <title>, one meta description and one canonical per URL, from published content only.
- Drafts, previews and Vercel preview deployments send noindex (or are not publicly reachable).
- The sitemap is built from a GROQ query, lists only canonical URLs, and updates on publish.
- Translated documents output reciprocal hreflang tags, including x-default.
- Key templates (articles, products, organisation, FAQs) output valid JSON-LD.
- Changed slugs create a 301 redirect instead of a 404.
- Editors see a SERP preview and length/keyword feedback before they publish.
- Search Console is connected so you can see which documents actually earn clicks.
Sanity SEO tools
You don't need a plugin, but it saves building the same fields on every project. Options include sanity-plugin-seofields (fields, previews, JSON-LD, dashboard), sanity-plugin-seo (scoring and readability), the Yoast-based seo-pane, and Sanity's own AI Assist for drafting metadata. The Sanity SEO plugin comparison goes through them side by side.
FAQ
Is Sanity good for SEO?
Yes, if your frontend renders server-side HTML. Sanity is a headless CMS: it stores content and leaves the HTML, meta tags and sitemap to your frontend (Next.js, Astro, Nuxt, SvelteKit, Remix). That gives you full control, but nothing is generated for you by default.
Does Sanity have built-in SEO fields?
No. Sanity ships no SEO schema. You either model the fields yourself or install a plugin such as sanity-plugin-seofields, which adds a complete seoFields type, previews and validation.
Does Sanity generate a sitemap?
No. Build the sitemap in your frontend from a GROQ query — in Next.js App Router that is an app/sitemap.ts file, shown in this guide.
Does Sanity automatically generate hreflang tags?
No. Sanity stores translations but does not output hreflang. You render the alternates in your frontend; seofields can build them from @sanity/document-internationalization translations.