Block Patterns API Overview
Block patterns are predefined block layouts that users can insert into content with a single click. Introduced in WordPress 5.5, patterns provide reusable design templates ranging from simple text layouts to complex multi-column designs.
Core Concepts
What Are Block Patterns?
Block patterns are collections of blocks that form a cohesive design unit. Unlike reusable blocks (synced patterns), block patterns are templates—inserting a pattern creates a copy that can be freely modified without affecting the original.
Pattern Properties:
name– Unique identifier with namespace (e.g.,my-plugin/hero-section)title– Human-readable display name (required)content– Block HTML markup orfilePathto a PHP file (required)description– Hidden text for search/discoverycategories– Array of category slugs for organizationkeywords– Search aliasesblockTypes– Blocks that can use this pattern (transforms, placeholders)postTypes– Restrict pattern to specific post typestemplateTypes– Template types where pattern fits (e.g.,404,single)viewportWidth– Preview width in inserterinserter– Whether visible in inserter (default: true)source– Origin of pattern (core, theme, plugin, pattern-directory)
Pattern Categories
Categories organize patterns in the inserter. WordPress registers these core categories:
| Category | Description |
|---|---|
banner |
Bold sections for key content |
buttons |
Button and CTA patterns |
columns |
Multi-column layouts |
text |
Text-focused patterns |
query / posts |
Post display layouts |
featured |
Curated high-quality patterns |
call-to-action |
Conversion-focused sections |
team |
Team member displays |
testimonials |
Reviews and feedback |
services |
Service descriptions |
contact |
Contact information |
about |
Introduction sections |
portfolio |
Work showcases |
gallery |
Image layouts |
media |
Video/audio layouts |
videos |
Video-specific layouts |
audio |
Audio-specific layouts |
header |
Site header designs |
footer |
Site footer designs |
Pattern Sources
WordPress loads patterns from multiple sources:
- Core Patterns – Built into WordPress (
wp-includes/block-patterns/) - Theme Patterns – From theme’s
patterns/directory - Plugin Patterns – Registered programmatically
- Remote Patterns – From wordpress.org/patterns (Pattern Directory)
- theme.json Patterns – Referenced by slug in theme.json
Registration Flow
┌─────────────────────────────────────────────────────────────────┐
│ WordPress Init │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 1. Core Categories Registered │
│ └─► _register_core_block_patterns_and_categories() │
│ │
│ 2. Core Patterns Registered (if theme supports) │
│ └─► query-standard-posts, query-grid-posts, etc. │
│ │
│ 3. Theme Patterns Registered │
│ └─► _register_theme_block_patterns() │
│ └─► Scans theme/patterns/ directory │
│ └─► Child theme overrides parent patterns │
│ │
│ 4. Remote Patterns Loaded (if enabled) │
│ └─► _load_remote_block_patterns() │
│ └─► _load_remote_featured_patterns() │
│ └─► _register_remote_theme_patterns() │
│ │
└─────────────────────────────────────────────────────────────────┘
Theme Pattern Files
Themes can define patterns as PHP files in the patterns/ directory:
<?php
/**
* Title: Hero Section
* Slug: my-theme/hero-section
* Categories: banner, featured
* Keywords: hero, header, intro
* Block Types: core/post-content
* Post Types: page
* Viewport Width: 1200
* Inserter: yes
*/
?>
<!-- wp:cover {"url":"..."} -->
<div class="wp-block-cover">
<!-- wp:heading -->
<h2>Welcome</h2>
<!-- /wp:heading -->
</div>
<!-- /wp:cover -->
File Header Fields:
Title– Pattern title (required)Slug– Unique pattern name (required)Categories– Comma-separated category slugsKeywords– Comma-separated search termsBlock Types– Comma-separated block typesPost Types– Comma-separated post type restrictionsTemplate Types– Comma-separated template typesViewport Width– Integer width for previewInserter–yesorno
Core Block Patterns
WordPress ships with query-focused patterns:
| Pattern | Description |
|---|---|
core/query-standard-posts |
Basic post list with title, image, excerpt |
core/query-medium-posts |
Medium-sized post layout |
core/query-small-posts |
Compact post listing |
core/query-grid-posts |
Grid layout for posts |
core/query-large-title-posts |
Large title emphasis |
core/query-offset-posts |
Offset/featured first post layout |
Theme Support
Themes control core pattern loading:
// Enable core patterns (default)
add_theme_support( 'core-block-patterns' );
// Disable core patterns
remove_theme_support( 'core-block-patterns' );
Pattern Directory Integration
Themes can reference patterns from wordpress.org/patterns in theme.json:
{
"patterns": [
"short-text-surrounded-by-round-images",
"partner-logos"
]
}
These patterns are fetched via the REST API and cached.
Block Hooks Integration
Since WordPress 6.5, pattern content is processed through the Block Hooks system:
$content = apply_block_hooks_to_content(
$content,
$pattern,
'insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata'
);
This allows hooked blocks to be inserted into pattern content automatically.
Best Practices
Pattern Naming
- Use namespace prefix:
theme-slug/pattern-nameorplugin-slug/pattern-name - Use lowercase with hyphens
- Be descriptive:
theme/hero-with-ctanottheme/pattern-1
Pattern Content
- Use semantic HTML structure
- Include placeholder content users will replace
- Use theme-aware values where possible (colors, fonts)
- Test with different content lengths
Performance
- Use
filePathfor lazy loading large patterns - Patterns in
patterns/directory are auto-cached - Remote patterns are cached via transients
Accessibility
- Include proper heading hierarchy
- Use meaningful alt text in placeholder images
- Ensure color contrast meets WCAG standards
Version History
| Version | Changes |
|---|---|
| 5.5.0 | Block Patterns API introduced |
| 5.8.0 | blockTypes property added |
| 5.9.0 | Pattern Directory integration |
| 6.0.0 | Theme patterns from patterns/ directory |
| 6.1.0 | postTypes property added |
| 6.2.0 | templateTypes property added |
| 6.3.0 | Pattern source tracking added |
| 6.4.0 | WP_Theme::get_block_patterns() method |
| 6.5.0 | filePath property for lazy loading |
Related APIs
- WP_Block_Patterns_Registry – Pattern registry class
- WP_Block_Pattern_Categories_Registry – Category registry
- Pattern Functions – Registration functions
- Pattern Hooks – Available filters and actions