# wp_maybe_add_fetchpriority_high_attr()

URL: https://chugunov.pro/api-wordpress/functions/wp_maybe_add_fetchpriority_high_attr/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 6.3.0.

## Сигнатура

```php
wp_maybe_add_fetchpriority_high_attr( $loading_attrs, string $tag_name, $attr ): array<string,
```

## Описание

Определяет, нужно ли добавлять `fetchpriority=’high’` к атрибутам загрузки.

## Параметры

- `$tag_name` `string` — обязательный. Имя тега.

## Возвращаемое значение

`array<string,`

## Исходный код

Файл: `wp-includes/media.php:6290`

```php
function wp_maybe_add_fetchpriority_high_attr( $loading_attrs, $tag_name, $attr ) {
	// For now, adding `fetchpriority="high"` is only supported for images.
	if ( 'img' !== $tag_name ) {
		return $loading_attrs;
	}

	$existing_fetchpriority = $attr['fetchpriority'] ?? null;
	if ( null !== $existing_fetchpriority && 'auto' !== $existing_fetchpriority ) {
		/*
		 * When an IMG has been explicitly marked with `fetchpriority=high`, then honor that this is the element that
		 * should have the priority. In contrast, the Navigation block may add `fetchpriority=low` to an IMG which
		 * appears in the Navigation Overlay; such images should never be considered candidates for
		 * `fetchpriority=high`. Lastly, block visibility may add `fetchpriority=auto` to an IMG when the block is
		 * conditionally displayed based on viewport size. Such an image is considered an LCP element candidate if it
		 * exceeds the threshold for the minimum number of square pixels.
		 */
		if ( 'high' === $existing_fetchpriority ) {
			$loading_attrs['fetchpriority'] = 'high';
			wp_high_priority_element_flag( false );
		}

		return $loading_attrs;
	}

	// Lazy-loading and `fetchpriority="high"` are mutually exclusive.
	if ( isset( $loading_attrs['loading'] ) && 'lazy' === $loading_attrs['loading'] ) {
		return $loading_attrs;
	}

	if ( ! wp_high_priority_element_flag() ) {
		return $loading_attrs;
	}

	/**
	 * Filters the minimum square-pixels threshold for an image to be eligible as the high-priority image.
	 *
	 * @since 6.3.0
	 *
	 * @param int $threshold Minimum square-pixels threshold. Default 50000.
	 */
	$wp_min_priority_img_pixels = apply_filters( 'wp_min_priority_img_pixels', 50000 );

	if ( $wp_min_priority_img_pixels <= $attr['width'] * $attr['height'] ) {
		if ( 'auto' !== $existing_fetchpriority ) {
			$loading_attrs['fetchpriority'] = 'high';
		}
		wp_high_priority_element_flag( false );
	}

	return $loading_attrs;
}
```

## История изменений

- 7.0.0 — Support is added for IMG tags with fetchpriority='low' and fetchpriority='auto'.
- 6.3.0 — Introduced.

## Связанные

Использует: [`wp_high_priority_element_flag`](https://chugunov.pro/api-wordpress/functions/wp_high_priority_element_flag/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: [`wp_get_loading_optimization_attributes`](https://chugunov.pro/api-wordpress/functions/wp_get_loading_optimization_attributes/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_maybe_add_fetchpriority_high_attr/
