wp_should_load_block_assets_on_demand()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_should_load_block_assets_on_demand(): bool
Описание
Когда функция возвращает true, другие функции обеспечивают загрузку ресурсов блоков только при рендеринге.
Когда функция возвращает false, все ресурсы блоков загружаются независимо от того, отображаются ли они на странице.
Возвращаемое значение по умолчанию зависит от результата wp_should_load_separate_core_block_assets(), который определяет, должны ли таблицы стилей блоков ядра загружаться по отдельности или через объединённую таблицу стилей ‘wp-block-library’.
Это влияет только на публичную часть сайта, но не на экраны редактора блоков.
См. alsowp_should_load_separate_core_block_assets()
Оригинал (английский)
When this function returns true, other functions ensure that blocks only load their assets on-render.
When this function returns false, all block assets are loaded regardless of whether they are rendered in a page.
The default return value depends on the result of wp_should_load_separate_core_block_assets(), which controls whether Core block stylesheets should be loaded separately or via a combined ‘wp-block-library’ stylesheet.
This only affects front end and not the block editor screens.
Возвращаемое значение
bool
Исходный код
wp-includes/script-loader.php:2728
function wp_should_load_block_assets_on_demand() {
if ( is_admin() || is_feed() || wp_is_rest_endpoint() ) {
return false;
}
/*
* For backward compatibility, the default return value for this function is based on the return value of
* `wp_should_load_separate_core_block_assets()`. Initially, this function used to control both of these concerns.
*/
$load_assets_on_demand = wp_should_load_separate_core_block_assets();
/**
* Filters whether block styles should be loaded on demand.
*
* Returning false loads all block assets, regardless of whether they are rendered in a page or not.
* Returning true loads block assets only when they are rendered.
*
* The default value of the filter depends on the result of wp_should_load_separate_core_block_assets(),
* which controls whether Core block stylesheets should be loaded separately or via a combined 'wp-block-library'
* stylesheet.
*
* @since 6.8.0
*
* @param bool $load_assets_on_demand Whether to load block assets only when they are rendered.
*/
return apply_filters( 'should_load_block_assets_on_demand', $load_assets_on_demand );
}
История изменений
| Версия | Описание |
|---|---|
| 6.8.0 | Introduced. |

