docs
FAQPage
Add FAQPage structured data to your Sanity-powered site with a single plugin. Surface expandable Q&A rich results directly in Google Search.
About FAQPage
FAQPage schema makes your FAQ content eligible for Google's rich results, showing expandable Q&A directly in search. Each question-and-answer pair is marked up so search engines can display them inline, boosting visibility and click-through rates.
Fields
| Field | Type | Required | Description |
|---|---|---|---|
mainEntity | array of objects | ✓ | List of Question objects, each with a name (question text) and acceptedAnswer.text (answer text). |
mainEntity[].name | string | ✓ | The full text of the question. |
mainEntity[].acceptedAnswer.text | string | ✓ | The full text of the answer to the question. |
Plugin Registration
sanity.config.ts
import { defineConfig } from "sanity";
import { schemaOrgFAQPagePlugin } from "sanity-plugin-seofields/schema";
export default defineConfig({
// ... your project config
plugins: [
schemaOrgFAQPagePlugin(),
],
});Schema Usage
Add theschemaOrgFAQPage field to any document schema:
schemas/page.ts
import { defineField, defineType } from 'sanity'
export default defineType({
name: 'page',
title: 'Page',
type: 'document',
fields: [
// ... your other fields
defineField({
name: 'schemaOrgFAQPage',
title: 'FAQ Page Schema',
type: 'schemaOrgFAQPage',
}),
],
})GROQ Query
GROQ query
const query = groq`*[_type == "page"][0]{
"faq": schemaOrgFAQPage {
mainEntity[] {
name,
"acceptedAnswer": acceptedAnswer { text }
}
}
}`;Next.js Component
app/layout.tsx
import { FAQPageSchema } from "sanity-plugin-seofields/react";
export default function Layout({ children }: { children: React.ReactNode }) {
// Fetch your FAQ data from Sanity
const faq = await sanityClient.fetch(query);
return (
<html lang="en">
<body>
<FAQPageSchema data={faq.faq} />
{children}
</body>
</html>
);
}JSON-LD Output
Generated JSON-LD
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "What is sanity-plugin-seofields?",
"acceptedAnswer": {
"@type": "Answer",
"text": "A Sanity plugin that adds SEO and structured data fields to your documents."
}
},
{
"@type": "Question",
"name": "How do I install it?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Run npm install sanity-plugin-seofields and add the plugin to your sanity.config.ts."
}
}
]
}Was this page helpful?