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-safebuildSeoMeta, sanitizeOGType, sanitizeTwitterCard
SeoMetaTags component
No Sanity Studio UI — safe in Next.js Server Components & generateMetadata()
Main Export
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().
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.
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
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 packagetitle: 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 fieldstitle: string (max 70)
description: text (max 160)
metaImage: image
keywords: string[]
canonicalUrl: url
metaAttributes: metaAttribute[]
openGraphStandalone Open Graph configurationtitle: 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 settingscard: '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 directivesnoIndex: boolean
noFollow: boolean
metaTagArray of custom meta attributesmetaAttributes: metaAttribute[]
metaAttributeIndividual meta attributekey?: string
type?: 'string' | 'image'
value?: string
image?: SanityImage
TypeScript Types
// 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
titledescriptioncanonicalUrlmetaImagekeywordsmetaAttributesrobotsOpen Graph
openGraphUrlopenGraphTitleopenGraphDescriptionopenGraphSiteNameopenGraphTypeopenGraphImageX (Twitter)
twitterCardtwitterSitetwitterCreatortwitterTitletwitterDescriptiontwitterImageWas this page helpful?