block_core_details_set_img_fetchpriority_low() │ WP 7.0.0

Sets fetchpriority="low" on all IMG tags within the collapsed Details block.

Images in a collapsed Details block are hidden until the block is expanded, so they should not compete with any resources in the critical rendering path, such as the LCP element image.

Хуков нет.

Возвращает

string. Modified HTML with fetchpriority="low" on all IMG tags when the showContent attribute is false.

Использование

block_core_details_set_img_fetchpriority_low( $block_content, $block ): string;
$block_content(строка) (обязательный)
The block content.
$block(массив) (обязательный)
The full block, including name and attributes.

Список изменений

С версии 7.0.0 Введена.

Код block_core_details_set_img_fetchpriority_low() WP 7.1.3

function block_core_details_set_img_fetchpriority_low( $block_content, array $block ): string {
	if ( ! is_string( $block_content ) ) {
		return '';
	}

	// If the Details block is open by default, short-circuit to let core add fetchpriority=high if appropriate.
	if ( $block['attrs']['showContent'] ?? false ) {
		return $block_content;
	}

	$tags = new WP_HTML_Tag_Processor( $block_content );
	while ( $tags->next_tag( 'IMG' ) ) {
		$tags->set_attribute( 'fetchpriority', 'low' );
	}
	return $tags->get_updated_html();
}