Skip to main content
seofields

Feature

Sanity meta tags that editors can actually maintain

Use sanity-plugin-seofields to add structured SEO fields to Sanity documents: meta title, description, canonical URL, keywords, robots controls, images, previews, and custom meta attributes.

Short answer: sanity-plugin-seofields adds a seoFields object to your Sanity documents with fields for meta title, description, canonical URL, keywords and robots, plus live previews and character guidance, so editors manage metadata without touching code.

Last updated

Why editors and developers like Sanity meta tag fields

Clean editor inputs

Editors work in labeled Sanity fields instead of asking developers to update page head markup.

Search-ready fields

Store title, description, canonical URL, keywords, robots directives, and images in one reusable object.

Preview before publish

Live previews and validation messages make missing or overlong metadata visible while content is being edited.

How Sanity meta tags flow from Studio to your head tag

1

Register the plugin

Add seofields() to sanity.config.ts so Sanity knows about seoFields and related object types.

2

Add seoFields

Place a field named seo on each document type that needs page-level metadata.

3

Render in your frontend

Query seo fields with GROQ and pass them to Next.js helpers or framework-neutral head helpers.

Sanity meta tags code examples

schemas/page.ts
import { defineField, defineType } from 'sanity'

export default defineType({
  name: 'page',
  title: 'Page',
  type: 'document',
  fields: [
    defineField({ name: 'title', type: 'string' }),
    defineField({
      name: 'slug',
      type: 'slug',
      options: { source: 'title' },
    }),
    defineField({
      name: 'seo',
      title: 'SEO',
      type: 'seoFields',
    }),
  ],
})
GROQ query
*[_type == "page" && slug.current == $slug][0]{
  title,
  "slug": slug.current,
  seo {
    title,
    description,
    canonicalUrl,
    keywords,
    metaImage { asset-> { url } },
    robots { noIndex, noFollow, noArchive }
  }
}
Framework-neutral head data
import { buildSeoHead } from 'sanity-plugin-seofields/head'

const head = buildSeoHead({
  seo: page.seo,
  baseUrl: 'https://example.com',
  path: `/${page.slug}`,
})

// head.title, head.meta, and head.link can be mapped into Astro, Nuxt,
// Vue, SvelteKit, Remix, or a custom renderer.

Sanity meta tags FAQ

What meta fields does seoFields include?

The main seoFields object includes title, description, meta image, keywords, canonical URL, robots settings, hreflang entries, Open Graph, X Cards, and preview fields.

Can I use a smaller schema than seoFields?

Yes. Use baseMeta when you only want title, description, image, keywords, canonical URL, and custom meta attributes.

Do editors need to know HTML meta tag syntax?

No. Editors fill in Sanity fields, and your frontend renders the tags through Next.js metadata APIs or framework-native head APIs.

Does the plugin create a sitemap?

No. Sitemap generation belongs in your frontend, but the stored SEO fields can be queried and used by your sitemap code.

Add editable metadata to Sanity

Start with the schema docs, then wire the queried fields into your frontend metadata layer.