render_block_core_post_featured_image() – Renders the `core/post-featured-image` block on the server.
You appear to be a bot. Output may be restricted
Description
Renders the core/post-featured-image
block on the server.
Usage
$string = render_block_core_post_featured_image( $attributes, $content, $block );
Parameters
- $attributes
- ( array ) required – Block attributes.
- $content
- ( string ) required – Block default content.
- $block
- ( WP_Block ) required – Block instance.
Returns
string Returns the featured image for the current post.
Source
File name: wordpress/wp-includes/blocks/post-featured-image.php
Lines:
1 to 50 of 50
function render_block_core_post_featured_image( $attributes, $content, $block ) { if ( ! isset( $block->context['postId'] ) ) { return ''; } $post_ID = $block->context['postId']; $is_link = isset( $attributes['isLink'] ) && $attributes['isLink']; $size_slug = isset( $attributes['sizeSlug'] ) ? $attributes['sizeSlug'] : 'post-thumbnail'; $post_title = trim( strip_tags( get_the_title( $post_ID ) ) ); $attr = get_block_core_post_featured_image_border_attributes( $attributes ); $overlay_markup = get_block_core_post_featured_image_overlay_element_markup( $attributes ); if ( $is_link ) { $attr['alt'] = $post_title; } if ( ! empty( $attributes['height'] ) ) { $extra_styles = "height:{$attributes['height']};"; if ( ! empty( $attributes['scale'] ) ) { $extra_styles .= "object-fit:{$attributes['scale']};"; } $attr['style'] = empty( $attr['style'] ) ? $extra_styles : $attr['style'] . $extra_styles; } $featured_image = get_the_post_thumbnail( $post_ID, $size_slug, $attr ); if ( ! $featured_image ) { return ''; } if ( $is_link ) { $link_target = $attributes['linkTarget']; $rel = ! empty( $attributes['rel'] ) ? 'rel="' . esc_attr( $attributes['rel'] ) . '"' : ''; $featured_image = sprintf( '<a href="%1$s" target="%2$s" %3$s>%4$s%5$s</a>', get_the_permalink( $post_ID ), esc_attr( $link_target ), $rel, $featured_image, $overlay_markup ); } else { $featured_image = $featured_image . $overlay_markup; } $wrapper_attributes = empty( $attributes['width'] ) ? get_block_wrapper_attributes() : get_block_wrapper_attributes( array( 'style' => "width:{$attributes['width']};" ) ); return "<figure {$wrapper_attributes}>{$featured_image}</figure>"; }