should_load_block_assets_on_demand filter-hookWP 6.8.0

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.

Usage

add_filter( 'should_load_block_assets_on_demand', 'wp_kama_should_load_block_assets_on_demand_filter' );

/**
 * Function for `should_load_block_assets_on_demand` filter-hook.
 * 
 * @param bool $load_assets_on_demand Whether to load block assets only when they are rendered.
 *
 * @return bool
 */
function wp_kama_should_load_block_assets_on_demand_filter( $load_assets_on_demand ){

	// filter...
	return $load_assets_on_demand;
}
$load_assets_on_demand(true|false)
Whether to load block assets only when they are rendered.

Changelog

Since 6.8.0 Introduced.

Where the hook is called

wp_should_load_block_assets_on_demand()
should_load_block_assets_on_demand
wp-includes/script-loader.php 2652
return apply_filters( 'should_load_block_assets_on_demand', $load_assets_on_demand );

Where the hook is used in WordPress

wp-includes/theme.php 4403
add_filter( 'should_load_block_assets_on_demand', '__return_true' );