Filter hook 'should_load_block_assets_on_demand'

in WP Core File wp-includes/script-loader.php at line 2674

View Source

should_load_block_assets_on_demand

Filter Hook
Description
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 {@see 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.

Hook Information

File Location wp-includes/script-loader.php View on GitHub
Hook Type Filter
Line Number 2674

Hook Parameters

Type Name Description
bool $load_assets_on_demand Whether to load block assets only when they are rendered.

Usage Examples

Basic Usage
<?php
// Hook into should_load_block_assets_on_demand
add_filter('should_load_block_assets_on_demand', 'my_custom_filter', 10, 1);

function my_custom_filter($load_assets_on_demand) {
    // Your custom filtering logic here
    return $load_assets_on_demand;
}

Source Code Context

wp-includes/script-loader.php:2674 - How this hook is used in WordPress core
<?php
2669  	 *
2670  	 * @since 6.8.0
2671  	 *
2672  	 * @param bool $load_assets_on_demand Whether to load block assets only when they are rendered.
2673  	 */
2674  	return apply_filters( 'should_load_block_assets_on_demand', $load_assets_on_demand );
2675  }
2676  
2677  /**
2678   * Enqueues registered block scripts and styles, depending on current rendered
2679   * context (only enqueuing editor scripts while in context of the editor).

PHP Documentation

<?php
/**
	 * 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 {@see 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.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 1
  • File: wp-includes/script-loader.php
Related Hooks

Related hooks will be displayed here in future updates.