Hide document types from "Create new document" button in Sanity Studio

25 replies
Last updated: Feb 23, 2022
Hello. Is there anyway to hide/remove/filter specific document types from this main “Create a new document” button at the top left of the studio?
AI Update

Yes! You can absolutely hide specific document types from the "Create new document" button using the newDocumentOptions configuration in your Studio config.

In your sanity.config.ts (or .js) file, you can add a document.newDocumentOptions function that filters which document types appear in the global create menu. Here's how:

import { defineConfig } from 'sanity'

export default defineConfig({
  // ... other config
  document: {
    newDocumentOptions: (prev, { currentUser, creationContext }) => {
      // Filter out specific document types
      return prev.filter(
        (template) => !['documentTypeToHide', 'anotherTypeToHide'].includes(template.templateId)
      )
    },
  },
})

You can also make this context-aware. For example, if you want to hide certain types only in specific places (like in the Structure tool but not in other contexts):

document: {
  newDocumentOptions: (prev, { currentUser, creationContext }) => {
    const { type, schemaType } = creationContext;
    
    // Hide 'pet' documents only when creating from Structure tool
    if (type === 'structure' && schemaType === 'pet') {
      return [];
    }
    
    return prev;
  },
}

The newDocumentOptions function receives:

  • prev: The default array of document creation options
  • currentUser: Information about the logged-in user (useful for role-based filtering)
  • creationContext: Where the creation is happening (Structure tool, global menu, etc.)

This is particularly useful for:

  • Hiding internal/system document types from content editors
  • Role-based restrictions (showing different document types to different users)
  • Context-specific creation (different options in different parts of your Studio)

You can find more details and examples in the newDocumentOptions recipe and the Studio customizations guide.

Show original thread
25 replies
I’m wondering about the same,
user F
. Here’re some docs about configuring the dashboard. I can see how to add new widgets but can not find how to remove some.
seems like it’s a default config that can not be changed
Can the button be removed/hidden?
As far as I can see the default config is coming from this library: https://github.com/sanity-io/sanity/tree/next/packages/%40sanity/default-layout . And it’s a required one to run a sanity studio. So I assume that to change the default dashboard, you need to make some changes to the library. BUT these are just mu assumptions ☺️
Good to know. I guess I would need to resort to using CSS to hide that button if possible.
Do you or anyone else know how this can be even targeted. Following this Sanity doc about “Styling the Studio ” and it triggers errors without even adding / customizing from what the docs day.
Also it seems like it’s just for overriding variables. Can any css be added to just include a line like
.button-class { display: none; }
work?
I do not think you can reach your goal with overwriting a css class in the studio. It’s the CreateDomunentDialog that has to be removed from I understand. But to do that you need to add changes to the widget itself.
OK…I see what you are saying. So I would need to possibly “extend” it and override it? Just not sure how this is possible
I think so. Maybe there’re easier ways to access this one but that my initial thoughts.
The easiest way to remove documents from that button, for now, is still using this soon-to-be deprecated feature:
https://www.sanity.io/docs/ui-affordances-for-actions
There are no clear ways to achieve this with other features mentioned in that doc (Initial value templates or custom document actions)
Is there anyway to hide/remove/filter specific document types from this main “Create a new document” button at the top left of the studio?
You can remove documents from that list using the following, though this will also remove the
Create
icon from the document list. Technically, you’ll still be able to create them at
/intent/create/template=<TYPE>;type=<TYPE>/
.
In sanity.json (path can be any file or name you want):

{
  "name": "part:@sanity/base/initial-value-templates",
  "path": "./initial-value-templates/initialValueTemplates.js"
},
In initialValueTemplates.js:


import T from '@sanity/base/initial-value-template-builder' // Edited to add. Good catch, Derek!

export default [
  ...T.defaults().filter(item => item.spec.schemaType !== 'schemaTypeToRemove'),
]
TIL, thanks Geoff! Perhaps should add that to the docs, in the experiment actions section and also the structure builder example where the experiment actions are still recommended
Thanks
user A
, this is exactly what I was looking for. Thank you!
Hi
user A
, I tried this for a document type
event
and it is still showing…can you please check this out and let me know what I am doing wrong?
I've just given this a try, perhaps you need to import the builder?

import T from '@sanity/base/initial-value-template-builder'
But it's odd if you didn't see any errors
Whoops! Exactly what Derek said. Yes, you’ll need to add that to
initialValueTemplates.js
.
I've just given this a try, perhaps you need to import the builder?

import T from '@sanity/base/initial-value-template-builder'
But it's odd if you didn't see any errors
Whoops! Exactly what Derek said. Yes, you’ll need to add that to
initialValueTemplates.js
.
Awesome! That worked. Thanks for all your help
user A
,
user G
and
user M
!
Perhaps should add that to the docs
user G
Will do. There are some differences between the two APIs that need to be confirmed, but I agree that it should be there. Thanks! 🙌
Thank you for the help,
user A
user G
!! it turned out to be easier then going into the default-layout library and expanding it as I thought. ☺️🙏 Hope you got it working,
user F
💪
Circle back to add this bit; the code
user A
shared removes the doc from the menu but doesn't prevent editors from (hopfully) accidentally removing / unpublishing the doc. In order to do that we'd need to add a custom document action as well:

// sanity.json 
//... 
"parts": [ 
  //... 
  { 
    "implements": "part:@sanity/base/document-actions/resolver", 
    "path": "resolveDocumentActions.js" 
  } 
]

// resolveDocumentActions.js
import defaultResolve, {
  PublishAction,
  DiscardChangesAction,
} from 'part:@sanity/base/document-actions'

export default function resolveDocumentActions(props) {
  if (['dont', 'delete', 'me'].includes(props.type)) {
    return defaultResolve(props).filter((action) =>
      [PublishAction, DiscardChangesAction].includes(action)
    )
  } else {
    return defaultResolve(props)
  }
}
Circle back to add this bit; the code
user A
shared removes the doc from the menu but doesn't prevent editors from (hopfully) accidentally removing / unpublishing the doc. In order to do that we'd need to add a custom document action as well:

// sanity.json 
//... 
"parts": [ 
  //... 
  { 
    "implements": "part:@sanity/base/document-actions/resolver", 
    "path": "resolveDocumentActions.js" 
  } 
]

// resolveDocumentActions.js
import defaultResolve, {
  PublishAction,
  DiscardChangesAction,
} from 'part:@sanity/base/document-actions'

export default function resolveDocumentActions(props) {
  if (['dont', 'delete', 'me'].includes(props.type)) {
    return defaultResolve(props).filter((action) =>
      [PublishAction, DiscardChangesAction].includes(action)
    )
  } else {
    return defaultResolve(props)
  }
}

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.

Was this answer helpful?