wp-includes/blocks/post-featured-image.php:18Renders the core/post-featured-image block on the server.
$attributesarray$contentstring$blockWP_Blockstringfunction 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 = $attributes['sizeSlug'] ?? 'post-thumbnail'; $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 ) { $title = get_the_title( $post_ID ); if ( $title ) { $attr['alt'] = trim( strip_tags( $title ) ); } else { $attr['alt'] = sprintf( // translators: %d is the post ID. __( 'Untitled post %d' ), $post_ID ); } } $extra_styles = ''; $has_width = array_key_exists( 'width', $attributes ) && null !== $attributes['width'] && '' !== $attributes['width']; $has_height = array_key_exists( 'height', $attributes ) && null !== $attributes['height'] && '' !== $attributes['height']; if ( ! empty( $attributes['aspectRatio'] ) ) { // If there's no non-default value set, let the image's width and height attributes determine its intrinsic aspect ratio. if ( 'auto' !== $attributes['aspectRatio'] ) { $extra_styles .= esc_attr( safecss_filter_attr( 'aspect-ratio:' . $attributes['aspectRatio'] ) ) . ';'; } $extra_styles .= 'width:100%;'; } if ( $has_height ) { $extra_styles .= esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . ';'; } elseif ( $has_width ) { $extra_styles .= 'height:auto;'; } if ( $has_width ) { $extra_styles .= esc_attr( safecss_filter_attr( 'width:' . $attributes['width'] ) ) . ';'; } if ( ! empty( $attributes['scale'] ) ) { $extra_styles .= esc_attr( safecss_filter_attr( 'object-fit:' . $attributes['scale'] ) ) . ';'; } if ( ! empty( $attributes['style']['shadow'] ) ) { $shadow_styles = wp_style_engine_get_styles( array( 'shadow' => $attributes['style']['shadow'] ) ); if ( ! empty( $shadow_styles['css'] ) ) { $extra_styles .= $shadow_styles['css']; } } if ( ! empty( $extra_styles ) ) { $attr['style'] = empty( $attr['style'] ) ? $extra_styles : $attr['style'] . $extra_styles; } $featured_image = get_the_post_thumbnail( $post_ID, $size_slug, $attr ); // Get the first image from the post. if ( $attributes['useFirstImageFromPost'] && ! $featured_image ) { $content_post = get_post( $post_ID ); $content = $content_post->post_content; $processor = new WP_HTML_Tag_Processor( $content ); /* * Transfer the image tag from the post into a new text snippet. * Because the HTML API doesn't currently expose a way to extract * HTML substrings this is necessary as a workaround. Of note, this * is different than directly extracting the IMG tag: * - If there are duplicate attributes in the source there will only be one in the output. * - If there are single-quoted or unquoted attributes they will be double-quoted in the output. * - If there are named character references in the attribute values they may be replaced with their direct code points. E.g. `…` becomes `…`. * In the future there will likely be a mechanism to copy snippets of HTML from * one document into another, via the HTML Processor's `get_outer_html()` or * equivalent. When that happens it would be appropriate to replace this customIntroduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-includes/blocks/post-featured-image.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.