This code snippet provides a custom WordPress hook to filter posts dynamically based on specific conditions such as post meta, categories, or tags. It...
Back to Snippets
php
• 29 lines
Register Custom Gutenberg Block Pattern
Register a custom Gutenberg block pattern with category — reusable hero section pattern with heading, paragraph, and CTA button.
Snippet Stats
Lines
29
Characters
757
Read
1 min
/**
* Register a custom block pattern for a hero section.
*/
add_action( 'init', function(): void {
register_block_pattern_category( 'mytheme', array(
'label' => __( 'My Theme', 'theme-domain' ),
) );
register_block_pattern( 'mytheme/hero-section', array(
'title' => __( 'Hero Section', 'theme-domain' ),
'description' => __( 'A full-width hero with heading, paragraph, and CTA button.', 'theme-domain' ),
'categories' => array( 'mytheme' ),
'content' => '
' . esc_html__( 'Build Something Amazing', 'theme-domain' ) . '
' . esc_html__( 'Start your next project with production-ready code.', 'theme-domain' ) . '
' . esc_html__( 'Get Started', 'theme-domain' ) . '
',
) );
} );
Found an issue with this snippet? Help us improve by reporting it. Report it →