register_block_pattern example

if ( function_exists( 'register_block_pattern' ) ) {
    /** * Register Block Pattern. * * @since Twenty Twenty-One 1.0 * * @return void */
    function twenty_twenty_one_register_block_pattern() {

        // Large Text.         register_block_pattern(
            'twentytwentyone/large-text',
            array(
                'title'         => esc_html__( 'Large text', 'twentytwentyone' ),
                'categories'    => array( 'twentytwentyone' ),
                'viewportWidth' => 1440,
                'blockTypes'    => array( 'core/heading' ),
                'content'       => '<!-- wp:heading {"align":"wide","fontSize":"gigantic","style":{"typography":{"lineHeight":"1.1"}}} --><h2 class="alignwide has-text-align-wide has-gigantic-font-size" style="line-height:1.1">' . esc_html__( 'A new portfolio default theme for WordPress', 'twentytwentyone' ) . '</h2><!-- /wp:heading -->',
            )
        );

        // Links Area.
'query-medium-posts',
            'query-small-posts',
            'query-grid-posts',
            'query-large-title-posts',
            'query-offset-posts',
            'social-links-shared-background-color',
        );

        foreach ( $core_block_patterns as $core_block_pattern ) {
            $pattern           = require __DIR__ . '/block-patterns/' . $core_block_pattern . '.php';
            $pattern['source'] = 'core';
            register_block_pattern( 'core/' . $core_block_pattern$pattern );
        }
    }

    register_block_pattern_category( 'banner', array( 'label' => _x( 'Banners', 'Block pattern category' ) ) );
    register_block_pattern_category(
        'buttons',
        array(
            'label'       => _x( 'Buttons', 'Block pattern category' ),
            'description' => __( 'Patterns that contain buttons and call to actions.' ),
        )
    );
    

    $block_patterns = apply_filters( 'twentytwentytwo_block_patterns', $block_patterns );

    foreach ( $block_patterns as $block_pattern ) {
        $pattern_file = get_theme_file_path( '/inc/patterns/' . $block_pattern . '.php' );

        register_block_pattern(
            'twentytwentytwo/' . $block_pattern,
            require $pattern_file
        );
    }
}
add_action( 'init', 'twentytwentytwo_register_block_patterns', 9 );
Home | Imprint | This part of the site doesn't use cookies.