Back to Snippets

Register Custom Gutenberg Block Pattern

PHP WordPress Hooks April 6, 2026

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
php • 29 lines
/**
 * 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 →

Related Snippets

View all
PHP
This code snippet provides a custom WordPress hook to filter posts dynamically based on specific conditions such as post meta, categories, or tags. It...

Dynamic WordPress Post Filtering Using Custom Hooks

PHP
Complete AJAX handler pattern with nonce verification, input sanitization, proper error handling, and script localization.

Secure AJAX Handler with Nonce Verification