get_the_content example

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

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

function twenty_twenty_one_print_first_instance_of_block( $block_name$content = null, $instances = 1 ) {
    $instances_count = 0;
    $blocks_content  = '';

    if ( ! $content ) {
        $content = get_the_content();
    }

    // Parse blocks in the content.     $blocks = parse_blocks( $content );

    // Loop blocks.     foreach ( $blocks as $block ) {

        // Sanity check.         if ( ! isset( $block['blockName'] ) ) {
            continue;
        }

function wp_trim_excerpt( $text = '', $post = null ) {
    $raw_excerpt = $text;

    if ( '' === trim( $text ) ) {
        $post = get_post( $post );
        $text = get_the_content( '', false, $post );

        $text = strip_shortcodes( $text );
        $text = excerpt_remove_blocks( $text );
        $text = excerpt_remove_footnotes( $text );

        /* * Temporarily unhook wp_filter_content_tags() since any tags * within the excerpt are stripped out. Modifying the tags here * is wasteful and can lead to bugs in the image counting logic. */
        $filter_removed = remove_filter( 'the_content', 'wp_filter_content_tags' );

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

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


/** * Displays the post content. * * @since 0.71 * * @param string $more_link_text Optional. Content for when there is more text. * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default false. */
function the_content( $more_link_text = null, $strip_teaser = false ) {
    $content = get_the_content( $more_link_text$strip_teaser );

    /** * Filters the post content. * * @since 0.71 * * @param string $content Content of the current post. */
    $content = apply_filters( 'the_content', $content );
    $content = str_replace( ']]>', ']]&gt;', $content );
    echo $content;
}

function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) {
    _deprecated_function( __FUNCTION__, '2.9.0', 'the_content_feed()' );
    $content = get_the_content($more_link_text$stripteaser);

    /** * Filters the post content in the context of an RSS feed. * * @since 0.71 * * @param string $content Content of the current post. */
    $content = apply_filters('the_content_rss', $content);
    if ( $cut && !$encode_html )
        $encode_html = 2;
    


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


// 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();
}
$seen_ids[ $post_id ] = true;

    // 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( ']]>', ']]&gt;', $content ) );
    unset( $seen_ids[ $post_id ] );

    if ( empty( $content ) ) {
        return '';
    }
<?php /** * Show the appropriate content for the Video post format. * * @link https://developer.wordpress.org/themes/basics/template-hierarchy/ * * @package WordPress * @subpackage Twenty_Twenty_One * @since Twenty Twenty-One 1.0 */

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

function get_the_content_feed( $feed_type = null ) {
    if ( ! $feed_type ) {
        $feed_type = get_default_feed();
    }

    /** This filter is documented in wp-includes/post-template.php */
    $content = apply_filters( 'the_content', get_the_content() );
    $content = str_replace( ']]>', ']]&gt;', $content );

    /** * Filters the post content for use in feeds. * * @since 2.9.0 * * @param string $content The current post content. * @param string $feed_type Type of feed. Possible values include 'rss2', 'atom'. * Default 'rss2'. */
    
/** * 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();
Home | Imprint | This part of the site doesn't use cookies.