How to add Sanity icon to portable text links instead of emoji?
Looking at the guide for internal and external links with Portable Text, I can see what's happening here! The screenshot in the guide shows a nice Sanity icon in the Portable Text toolbar, but you're getting an emoji instead.
The issue is that when you define custom annotations in your Portable Text schema, you need to explicitly specify an icon property to get that Sanity icon to show up. Without it, the editor falls back to a default icon (which appears to be that emoji you're seeing).
Here's how to fix it - when you define your annotation in your schema, import an icon from the @sanity/icons package and add it to your annotation definition:
import { LinkIcon } from '@sanity/icons'
// In your portableText schema:
marks: {
annotations: [
{
name: 'link',
type: 'object',
title: 'External link',
icon: LinkIcon, // Add this!
fields: [
{
name: 'href',
type: 'url',
title: 'URL'
}
]
}
]
}For internal links, you might want to use a different icon to distinguish them:
import { LinkIcon, DocumentIcon } from '@sanity/icons'
annotations: [
{
name: 'internalLink',
type: 'object',
title: 'Internal link',
icon: DocumentIcon, // Or any other icon you prefer
fields: [...]
}
]You can browse all available icons in the @sanity/icons package here. Popular choices for links include LinkIcon, ExternalLinkIcon, DocumentIcon, or even the Sanity monogram if you want that specific branding look.
Make sure your schema file has a .jsx or .tsx extension when using icons, and don't forget to install the package if you haven't already: npm install @sanity/icons
Show original thread7 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.