has_block example



$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();
}


// 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();
}
/** * Show the appropriate content for the Link post format. * * @link https://developer.wordpress.org/themes/basics/template-hierarchy/ * * @package WordPress * @subpackage Twenty_Twenty_One * @since Twenty Twenty-One 1.0 */

// 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();
}


// 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/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();
// Check is needed for backward compatibility with third-party plugins     // that might rely on the `in_the_loop` check; calling `the_post` sets it to true.     if ( ! in_the_loop() && have_posts() ) {
        the_post();
    }

    // When inside the main loop, we want to use queried object     // so that `the_preview` for the current post can apply.     // We force this behavior by omitting the third argument (post ID) from the `get_the_content`.     $content = get_the_content();
    // Check for nextpage to display page links for paginated posts.     if ( has_block( 'core/nextpage' ) ) {
        $content .= wp_link_pages( array( 'echo' => 0 ) );
    }

    /** This filter is documented in wp-includes/post-template.php */
    $content = apply_filters( 'the_content', str_replace( ']]>', ']]>', $content ) );
    unset( $seen_ids[ $post_id ] );

    if ( empty( $content ) ) {
        return '';
    }

    
/** * Show the appropriate content for the Gallery post format. * * @link https://developer.wordpress.org/themes/basics/template-hierarchy/ * * @package WordPress * @subpackage Twenty_Twenty_One * @since Twenty Twenty-One 1.0 */

// 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();


    // If the requested page doesn't exist.     if ( $elements['page'] > count( $elements['pages'] ) ) {
        // Give them the highest numbered page that DOES exist.         $elements['page'] = count( $elements['pages'] );
    }

    $page_no = $elements['page'];
    $content = $elements['pages'][ $page_no - 1 ];
    if ( preg_match( '/<!--more(.*?)?-->/', $content$matches ) ) {
        if ( has_block( 'more', $content ) ) {
            // Remove the core/more block delimiters. They will be left over after $content is split up.             $content = preg_replace( '/<!-- \/?wp:more(.*?) -->/', '', $content );
        }

        $content = explode( $matches[0]$content, 2 );

        if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
            $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
        }

        $has_teaser = true;
    }

function get_post_galleries( $post$html = true ) {
    $post = get_post( $post );

    if ( ! $post ) {
        return array();
    }

    if ( ! has_shortcode( $post->post_content, 'gallery' ) && ! has_block( 'gallery', $post->post_content ) ) {
        return array();
    }

    $galleries = array();
    if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ) ) {
        foreach ( $matches as $shortcode ) {
            if ( 'gallery' === $shortcode[2] ) {
                $srcs = array();

                $shortcode_attrs = shortcode_parse_atts( $shortcode[3] );
                if ( ! is_array( $shortcode_attrs ) ) {
                    


$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();
Home | Imprint | This part of the site doesn't use cookies.