block_core_navigation_set_overlay_image_fetch_priority()WP 7.0.0

Sets fetchpriority="low" on all IMG tags within the navigation overlay.

Images in the overlay are hidden until the menu is opened, so they should not compete with any actual LCP element image on the page.

No Hooks.

Returns

String. Modified HTML with fetchpriority="low" on all IMG tags.

Usage

block_core_navigation_set_overlay_image_fetch_priority( $overlay_blocks_html ): string;
$overlay_blocks_html(string) (required)
The rendered HTML of the overlay blocks.

Changelog

Since 7.0.0 Introduced.

block_core_navigation_set_overlay_image_fetch_priority() code WP 7.0

function block_core_navigation_set_overlay_image_fetch_priority( string $overlay_blocks_html ): string {
	$tags = new WP_HTML_Tag_Processor( $overlay_blocks_html );
	while ( $tags->next_tag( 'IMG' ) ) {
		$tags->set_attribute( 'fetchpriority', 'low' );
	}
	return $tags->get_updated_html();
}