
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeFor creating WordPress-like shortcode functionality in Sanity, you should use inline blocks (also called inline objects) rather than annotations. Here's why:
Inline blocks are the better choice for shortcode-like functionality because:
children array alongside text spansAnnotations are designed for marking up text with metadata (like links, citations, or highlighting) and work differently - they use markDefs and apply marks to text spans.
You add inline blocks by including an of property in your block type definition:
import { defineType } from 'sanity'
export default defineType({
name: 'blockContent',
type: 'array',
of: [
{
type: 'block',
of: [
{
name: 'productPrice',
type: 'object',
fields: [
{name: 'productId', type: 'string'},
{name: 'region', type: 'string'}
]
}
]
}
]
})This creates a button in the Portable Text Editor toolbar that lets editors insert your inline block directly into paragraphs - just like WordPress shortcodes!
Inline blocks appear in the JSON output alongside text spans in the children array:
"children": [
{
"_type": "span",
"text": "This product costs "
},
{
"_type": "productPrice",
"productId": "abc123",
"region": "US"
},
{
"_type": "span",
"text": " in your region."
}
]When you query and render this content, you'll need to resolve any references in your GROQ query and create custom serializers for your inline blocks in your Portable Text renderer (using @portabletext/react or similar).
The key difference from Gutenberg's shortcode block: Sanity's inline blocks can truly be inline within a paragraph, not just standalone blocks. This gives you the WordPress shortcode experience where dynamic content flows naturally within text.
For more details on implementation, check out the guide on adding inline blocks to Portable Text.
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