How to hide a document from the Sanity Studio left nav using code snippets.
Yes, absolutely! You can hide document types from the left navigation in Sanity Studio using the Structure Builder. This is a common pattern when you have "child" documents (like sections, blocks, or components) that should only be referenced from within other documents, not managed directly from the main navigation.
By default, the Structure tool displays all document types in your schema. To hide specific types, you need to explicitly define which document types should appear in the navigation using the Structure Builder API.
Here's how to do it in your sanity.config.ts:
import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'
export default defineConfig({
// ...other config
plugins: [
structureTool({
structure: (S) =>
S.list()
.title('Content')
.items([
// Only list the document types you want to show
S.documentTypeListItem('page').title('Pages'),
S.documentTypeListItem('post').title('Blog Posts'),
// Don't include 'pageSection' or other child document types here
])
}),
// ...other plugins
],
})In this example, if you have a pageSection document type that's only referenced from within page documents, it won't appear in the left navigation because it's not included in the .items([]) array.
Key points:
- Once you define a custom structure, only the document types you explicitly list will appear in the navigation
- Hidden document types are still fully functional—they can be created, edited, and referenced through the normal reference/relationship fields
- You can still access them directly via URL if needed (like
/structure/pageSection) - This doesn't affect permissions or API access, just the Studio UI navigation
This approach gives you complete control over your Studio's content organization and helps keep the navigation clean for your editors!
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.