How to fix "untitled" document name in Sanity schema type?
The issue you're seeing is because your schema doesn't have a preview configuration set up! When Sanity doesn't know which field to use as the document title, it defaults to showing "untitled" everywhere.
Here's how to fix it - you need to add a preview configuration to your 'content' schema type. This tells Sanity which field to display as the title:
export default {
name: 'content',
type: 'document',
fields: [
{
name: 'title',
type: 'string',
title: 'Title'
},
// your other fields...
],
preview: {
select: {
title: 'title' // This tells Sanity to use the 'title' field
}
}
}The preview configuration uses two parts:
select: Specifies which fields to pull from your documentprepare(optional): Lets you transform the data before display
If you want to get fancier, you can add subtitles and media too:
preview: {
select: {
title: 'title',
subtitle: 'description',
media: 'coverImage'
}
}Or use the prepare function for custom formatting:
preview: {
select: {
title: 'title',
publishedAt: 'publishedAt'
},
prepare({title, publishedAt}) {
return {
title: title,
subtitle: publishedAt ? `Published: ${publishedAt}` : 'Draft'
}
}
}Once you add this to your schema and save, your documents should show their actual title instead of "untitled" in lists, references, and search results!
Show original thread15 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.