Slug not auto-generating when clicking 'Generate' button
Based on the slug field documentation, when the "Generate" button isn't working, here are the most common causes and solutions:
1. Check your source field configuration
The most likely issue is that your source field isn't properly configured. Make sure you have a source specified in your slug field definition:
{
name: 'slug',
type: 'slug',
options: {
source: 'title' // or whatever field you want to generate from
}
}2. Verify the source field has content
The Generate button won't work if the source field (like title) is empty. Make sure you've entered content in the source field before clicking Generate.
3. Check for reference-based sources
If you're trying to generate a slug from a reference field, you may need additional configuration. The source needs to properly resolve the referenced document's data:
source: doc => doc.referencedField?.title4. Custom slugify function issues
If you're using a custom slugify function in your options, make sure it's returning a valid string. A broken custom function will prevent slug generation from working.
5. Studio environment requirement
Important to note: slug generation only works within Sanity Studio itself. If you're trying to create documents via the HTTP API or programmatically, you'll need to implement your own slugification function (Sanity uses speakingurl internally).
If you can share the specific code from your schema definition, I can help pinpoint the exact issue! The most common fix is simply ensuring the source option is correctly defined and points to a field with actual content.
Show original thread4 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.