twenty_twenty_one_print_first_instance_of_block example



// If there is no featured-image, print the first image block found. if (
    ! twenty_twenty_one_can_show_post_thumbnail() &&
    has_block( 'core/image', get_the_content() )
) {

    twenty_twenty_one_print_first_instance_of_block( 'core/image', get_the_content() );
}

the_excerpt();


$content = get_the_content();

if ( has_block( 'core/audio', $content ) ) {
    twenty_twenty_one_print_first_instance_of_block( 'core/audio', $content );
} elseif ( has_block( 'core/embed', $content ) ) {
    twenty_twenty_one_print_first_instance_of_block( 'core/embed', $content );
} else {
    twenty_twenty_one_print_first_instance_of_block( 'core-embed/*', $content );
}

// Add the excerpt. the_excerpt();


$content = get_the_content();

// If there is no quote or pullquote print the content. if ( has_block( 'core/quote', $content ) ) {
    twenty_twenty_one_print_first_instance_of_block( 'core/quote', $content );
} elseif ( has_block( 'core/pullquote', $content ) ) {
    twenty_twenty_one_print_first_instance_of_block( 'core/pullquote', $content );
} else {
    the_excerpt();
}


// Print the 1st gallery found. if ( has_block( 'core/gallery', get_the_content() ) ) {

    twenty_twenty_one_print_first_instance_of_block( 'core/gallery', get_the_content() );
}

the_excerpt();


$content = get_the_content();

if ( has_block( 'core/video', $content ) ) {
    twenty_twenty_one_print_first_instance_of_block( 'core/video', $content );
} elseif ( has_block( 'core/embed', $content ) ) {
    twenty_twenty_one_print_first_instance_of_block( 'core/embed', $content );
} else {
    twenty_twenty_one_print_first_instance_of_block( 'core-embed/*', $content );
}

// Add the excerpt. the_excerpt();


// If there are paragraph blocks, print up to two. // Otherwise this is legacy content, so print the excerpt. if ( has_block( 'core/paragraph', get_the_content() ) ) {

    twenty_twenty_one_print_first_instance_of_block( 'core/paragraph', get_the_content(), 2 );
} else {

    the_excerpt();
}


// Print the 1st instance of a paragraph block. If none is found, print the content. if ( has_block( 'core/paragraph', get_the_content() ) ) {

    twenty_twenty_one_print_first_instance_of_block( 'core/paragraph', get_the_content() );
} else {

    the_content();
}
Home | Imprint | This part of the site doesn't use cookies.