Skip to main content
seofields
docs

API Reference

Complete reference for the plugin's exports, configuration types, and schema types.

Entry Points

sanity-plugin-seofieldsSanity Studio plugin (not RSC-safe)

default export — plugin factory

SeoHealthDashboard, SeoHealthTool, createSeoHealthPane

schema helpers, type exports, buildSeoMeta, SeoMetaTags

sanity-plugin-seofields/next✓ RSC-safe

buildSeoMeta, sanitizeOGType, sanitizeTwitterCard

SeoMetaTags component

No Sanity Studio UI — safe in Next.js Server Components & generateMetadata()

Main Export

Import
import seofields from 'sanity-plugin-seofields'
import type { SeoFieldsPluginConfig } from 'sanity-plugin-seofields'

// Usage
seofields(config?: SeoFieldsPluginConfig)

buildSeoMeta(options)

Converts a Sanity SEO object into a structured metadata object compatible with Next.js App Router's Metadata type. Import from sanity-plugin-seofields/next — safe to use in Next.js Server Components and generateMetadata().

buildSeoMeta
import { buildSeoMeta } from 'sanity-plugin-seofields/next'

const metadata = buildSeoMeta({
  seo: data.seo,              // Sanity SEO object (or null/undefined)
  baseUrl: 'https://example.com',
  path: '/about',
  defaults: {
    title: 'My Site',
    siteName: 'My Site',
    twitterSite: '@mysite',
    ogImage: 'https://example.com/og-default.png',
  },
  imageUrlResolver: (img) => urlFor(img).width(1200).url(),
})

// Returns: { title, description, keywords, robots, openGraph, twitter, alternates, other }

<SeoMetaTags>

Framework-agnostic React component that renders all SEO meta tags as plain React elements. Renders <title>, <meta name/property>, and <link rel="canonical">. Import from sanity-plugin-seofields/next to avoid RSC crashes.

SeoMetaTagsProps
import { SeoMetaTags } from 'sanity-plugin-seofields/next'
import type { SeoMetaTagsProps } from 'sanity-plugin-seofields/next'

interface SeoMetaTagsProps {
  data?: Partial<SeoFields> | null       // Raw Sanity SEO object
  baseUrl?: string                       // e.g. "https://example.com"
  path?: string                          // e.g. "/about"
  defaults?: SeoMetaDefaults             // Fallback values
  imageUrlResolver?: (img) => string     // Resolve Sanity image refs
}

SeoFieldsPluginConfig

SeoFieldsPluginConfig
interface SeoFieldsPluginConfig {
  // Enable/disable SEO preview (default: true)
  seoPreview?: boolean | {
    prefix?: (document: SanityDocument) => string
  }

  // Base URL for preview generation
  baseUrl?: string

  // Customize field titles and descriptions
  fieldOverrides?: {
    [fieldKey: string]: {
      title?: string
      description?: string
    }
  }

  // Hide fields on specific document types
  fieldVisibility?: {
    [documentType: string]: {
      hiddenFields: string[]
    }
  }

  // Hide fields globally
  defaultHiddenFields?: string[]

  // Enable/disable dashboard (default: true)
  enableDashboard?: boolean
}

Schema Types

These types are automatically registered when you add the plugin:

seoFieldsComplete SEO field package

title: string (max 70)

description: text (max 160)

canonicalUrl: url

metaImage: image

keywords: string[]

robots: { noIndex, noFollow }

metaAttributes: metaAttribute[]

openGraph: { title, description, url, siteName, type, image }

twitter: { card, site, creator, title, description, image }

baseMetaStandalone core meta fields

title: string (max 70)

description: text (max 160)

metaImage: image

keywords: string[]

canonicalUrl: url

metaAttributes: metaAttribute[]

openGraphStandalone Open Graph configuration

title: string

description: text

url: url

siteName: string

type: 'website' | 'article' | 'profile' | 'book' | 'music' | 'video' | 'product'

imageType: 'upload' | 'url'

image: image

imageUrl: url

twitterX (formerly Twitter) Card settings

card: 'summary' | 'summary_large_image' | 'app' | 'player'

site: string (@handle)

creator: string (@handle)

title: string (max 70)

description: text (max 200)

imageType: 'upload' | 'url'

image: image

imageUrl: url

robotsSearch engine directives

noIndex: boolean

noFollow: boolean

metaTagArray of custom meta attributes

metaAttributes: metaAttribute[]

metaAttributeIndividual meta attribute

key?: string

type?: 'string' | 'image'

value?: string

image?: SanityImage

TypeScript Types

Type imports
// Main entry
import type {
  SeoFields,          // Full SEO object shape
  OpenGraphSettings,  // openGraph sub-object
  TwitterCardSettings,// twitter sub-object
  RobotsSettings,     // robots sub-object
  MetaAttribute,      // individual metaAttribute item
  SanityImage,
  SanityImageWithAlt,
} from 'sanity-plugin-seofields'

// /next entry
import type {

  BuildSeoMetaOptions,  // Options for buildSeoMeta()
  SeoMetaDefaults,      // defaults sub-object
  SeoMetadata,          // Return type of buildSeoMeta()
  SeoMetaTagsProps,     // Props for <SeoMetaTags>
  SeoFieldsInput,       // Permissive input type (accepts Sanity codegen output)
} from 'sanity-plugin-seofields/next'

Field Override Keys

Available keys for fieldOverrides and fieldVisibility.hiddenFields:

Core

titledescriptioncanonicalUrlmetaImagekeywordsmetaAttributesrobots

Open Graph

openGraphUrlopenGraphTitleopenGraphDescriptionopenGraphSiteNameopenGraphTypeopenGraphImage

X (Twitter)

twitterCardtwitterSitetwitterCreatortwitterTitletwitterDescriptiontwitterImage

Was this page helpful?