# wp_get_loading_attr_default()

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

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

> Устаревший элемент. Помечен устаревшим с версии 6.3.0.

## Сигнатура

```php
wp_get_loading_attr_default( string $context ): string|bool
```

## Описание

Эту функцию следует вызывать для тега и контекста только тогда, когда отложенная загрузка включена в целом.
Обычно функция возвращает ‘lazy’, но с помощью ряда эвристик пытается определить, вероятно ли, что текущий элемент окажется в видимой части страницы; в этом случае она возвращает логическое false, из-за чего атрибут loading у элемента будет опущен. Цель такого уточнения — избежать отложенной загрузки элементов, находящихся в пределах начальной области просмотра, что может негативно сказаться на производительности.
Внутри при каждом вызове для элемента в основном содержимом функция использует wp_increase_content_media_count(). Если элемент является самым первым элементом содержимого, атрибут loading будет опущен.
Это пороговое значение по умолчанию в 3 элемента содержимого, для которых атрибут loading опускается, можно настроить с помощью фильтра ‘wp_omit_loading_attr_threshold’.
См. alsowp_get_loading_optimization_attributes()

## Параметры

- `$context` `string` — обязательный. Контекст элемента, для которого запрашивается значение атрибута loading.

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

`string|bool` — loading 'lazy' 'eager' false loading

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

Файл: `wp-includes/deprecated.php:4703`

```php
function wp_get_loading_attr_default( $context ) {
	_deprecated_function( __FUNCTION__, '6.3.0', 'wp_get_loading_optimization_attributes()' );
	global $wp_query;

	// Skip lazy-loading for the overall block template, as it is handled more granularly.
	if ( 'template' === $context ) {
		return false;
	}

	/*
	 * Do not lazy-load images in the header block template part, as they are likely above the fold.
	 * For classic themes, this is handled in the condition below using the 'get_header' action.
	 */
	$header_area = WP_TEMPLATE_PART_AREA_HEADER;
	if ( "template_part_{$header_area}" === $context ) {
		return false;
	}

	// Special handling for programmatically created image tags.
	if ( 'the_post_thumbnail' === $context || 'wp_get_attachment_image' === $context ) {
		/*
		 * Skip programmatically created images within post content as they need to be handled together with the other
		 * images within the post content.
		 * Without this clause, they would already be counted below which skews the number and can result in the first
		 * post content image being lazy-loaded only because there are images elsewhere in the post content.
		 */
		if ( doing_filter( 'the_content' ) ) {
			return false;
		}

		// Conditionally skip lazy-loading on images before the loop.
		if (
			// Only apply for main query but before the loop.
			$wp_query->before_loop && $wp_query->is_main_query()
			/*
			 * Any image before the loop, but after the header has started should not be lazy-loaded,
			 * except when the footer has already started which can happen when the current template
			 * does not include any loop.
			 */
			&& did_action( 'get_header' ) && ! did_action( 'get_footer' )
		) {
			return false;
		}
	}

	/*
	 * The first elements in 'the_content' or 'the_post_thumbnail' should not be lazy-loaded,
	 * as they are likely above the fold.
	 */
	if ( 'the_content' === $context || 'the_post_thumbnail' === $context ) {
		// Only elements within the main query loop have special handling.
		if ( is_admin() || ! in_the_loop() || ! is_main_query() ) {
			return 'lazy';
		}

		// Increase the counter since this is a main query content element.
		$content_media_count = wp_increase_content_media_count();

		// If the count so far is below the threshold, return `false` so that the `loading` attribute is omitted.
		if ( $content_media_count <= wp_omit_loading_attr_threshold() ) {
			return false;
		}

		// For elements after the threshold, lazy-load them as usual.
		return 'lazy';
	}

	// Lazy-load by default for any unknown context.
	return 'lazy';
}
```

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

- 6.3.0 — Deprecated. Use wp_get_loading_optimization_attributes() instead.
- 5.9.0 — Introduced.

## Связанные

Использует: [`wp_increase_content_media_count`](https://chugunov.pro/api-wordpress/functions/wp_increase_content_media_count/), [`wp_omit_loading_attr_threshold`](https://chugunov.pro/api-wordpress/functions/wp_omit_loading_attr_threshold/), `WP_Query::is_main_query`, [`in_the_loop`](https://chugunov.pro/api-wordpress/functions/in_the_loop/), [`is_main_query`](https://chugunov.pro/api-wordpress/functions/is_main_query/), [`doing_filter`](https://chugunov.pro/api-wordpress/functions/doing_filter/), [`did_action`](https://chugunov.pro/api-wordpress/functions/did_action/), [`is_admin`](https://chugunov.pro/api-wordpress/functions/is_admin/), [`_deprecated_function`](https://chugunov.pro/api-wordpress/functions/_deprecated_function/).
Используется в: [`wp_img_tag_add_loading_attr`](https://chugunov.pro/api-wordpress/functions/wp_img_tag_add_loading_attr/).

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