# wp_load_classic_theme_block_styles_on_demand()

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

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

## Сигнатура

```php
wp_load_classic_theme_block_styles_on_demand()
```

## Описание

Эту функцию необходимо вызвать до wp_default_styles() и register_core_block_style_handles(), чтобы добавить фильтры, из-за которых wp_should_load_separate_core_block_assets() будет возвращать true.
См. also_add_default_theme_supports()

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

Файл: `wp-includes/script-loader.php:3684`

```php
function wp_load_classic_theme_block_styles_on_demand(): void {
	// This is not relevant to block themes, as they are opted in to loading separate styles on demand via _add_default_theme_supports().
	if ( wp_is_block_theme() ) {
		return;
	}

	/*
	 * Make sure that wp_should_output_buffer_template_for_enhancement() returns true even if there aren't any
	 * `wp_template_enhancement_output_buffer` filters added, but do so at priority zero so that applications which
	 * wish to stream responses can more easily turn this off.
	 */
	add_filter( 'wp_should_output_buffer_template_for_enhancement', '__return_true', 0 );

	// If a site has opted out of the template enhancement output buffer, then bail.
	if ( ! wp_should_output_buffer_template_for_enhancement() ) {
		return;
	}

	// The following two filters are added by default for block themes in _add_default_theme_supports().

	/*
	 * Load separate block styles so that the large block-library stylesheet is not enqueued unconditionally, and so
	 * that block-specific styles will only be enqueued when they are used on the page. A priority of zero allows for
	 * this to be easily overridden by themes which wish to opt out. If a site has explicitly opted out of loading
	 * separate block styles, then abort.
	 */
	add_filter( 'should_load_separate_core_block_assets', '__return_true', 0 );
	if ( ! wp_should_load_separate_core_block_assets() ) {
		return;
	}

	/*
	 * Also ensure that block assets are loaded on demand (although the default value is from should_load_separate_core_block_assets).
	 * As above, a priority of zero allows for this to be easily overridden by themes which wish to opt out. If a site
	 * has explicitly opted out of loading block styles on demand, then abort.
	 */
	add_filter( 'should_load_block_assets_on_demand', '__return_true', 0 );
	if ( ! wp_should_load_block_assets_on_demand() ) {
		return;
	}

	// Add hooks which require the presence of the output buffer. Ideally the above two filters could be added here, but they run too early.
	add_action( 'wp_template_enhancement_output_buffer_started', 'wp_hoist_late_printed_styles' );
}
```

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

- 7.0.0 — This is now invoked at the wp_default_styles action with priority 0 instead of at init with priority 8.
- 6.9.0 — Introduced.

## Связанные

Использует: [`wp_should_output_buffer_template_for_enhancement`](https://chugunov.pro/api-wordpress/functions/wp_should_output_buffer_template_for_enhancement/), [`wp_should_load_block_assets_on_demand`](https://chugunov.pro/api-wordpress/functions/wp_should_load_block_assets_on_demand/), [`wp_is_block_theme`](https://chugunov.pro/api-wordpress/functions/wp_is_block_theme/), [`wp_should_load_separate_core_block_assets`](https://chugunov.pro/api-wordpress/functions/wp_should_load_separate_core_block_assets/), [`add_filter`](https://chugunov.pro/api-wordpress/functions/add_filter/), [`add_action`](https://chugunov.pro/api-wordpress/functions/add_action/).

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