This code snippet filters WordPress post queries based on custom conditions, specifically by category, using the 'pre_get_posts' action hook. It is us...
Back to Snippets
php
• 29 lines
PHP
PHP
PHP
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 →
Related Snippets
View allThis code snippet provides a custom WordPress hook to filter posts dynamically based on specific conditions such as post meta, categories, or tags. It...
Complete AJAX handler pattern with nonce verification, input sanitization, proper error handling, and script localization.