
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeThe slug field in Sanity stores just the URL-friendly identifier (like the-title-of-the-project), but you absolutely can customize how slugs are generated to include content type prefixes! Here are a few approaches:
You can modify the source option in your slug field to include a prefix based on the document type:
{
name: 'slug',
type: 'slug',
options: {
source: (doc) => `projects/${doc.title}`,
maxLength: 96
}
}This will generate slugs like projects/the-title-of-the-project directly in the slug field.
For more control, use the slugify option to add custom logic:
{
name: 'slug',
type: 'slug',
options: {
source: 'title',
slugify: (input, schemaType, context) => {
const prefix = context.parentPath[0]._type === 'project' ? 'projects' : 'blog'
return `${prefix}/${input.toLowerCase().replace(/\s+/g, '-')}`
}
}
}Many developers prefer keeping slugs simple in Sanity and adding the content type prefix when building routes in their frontend application. For example, in Next.js:
// In your routing logic
const url = doc._type === 'project'
? `/projects/${doc.slug.current}`
: `/blog/${doc.slug.current}`This approach keeps your slugs cleaner and more portable, and it's easier to restructure your URL patterns later without migrating content.
The third option is generally recommended because it separates content concerns from routing logic, but all three approaches work depending on your needs. The slug field documentation covers the technical details of source and slugify options if you want to dive deeper.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store