Title: wp_should_load_block_assets_on_demand
Published: April 17, 2025
Last modified: August 20, 2026

---

# wp_should_load_block_assets_on_demand(): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#see-also)
 * [Return](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#changelog)

Checks whether block styles should be loaded only on-render.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#description)󠁿

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()](https://developer.wordpress.org/reference/functions/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.

### 󠀁[See also](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#see-also)󠁿

 * [wp_should_load_separate_core_block_assets()](https://developer.wordpress.org/reference/functions/wp_should_load_separate_core_block_assets/)

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#return)󠁿

 bool Whether to load block assets only when they are rendered.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#source)󠁿

    ```php
    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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/script-loader.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/script-loader.php#L2739)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/script-loader.php#L2739-L2765)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#hooks)󠁿

 [apply_filters( ‘should_load_block_assets_on_demand’, bool $load_assets_on_demand )](https://developer.wordpress.org/reference/hooks/should_load_block_assets_on_demand/)

Filters whether block styles should be loaded on demand.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_is_rest_endpoint()](https://developer.wordpress.org/reference/functions/wp_is_rest_endpoint/)`wp-includes/rest-api.php` |

Checks whether a REST API endpoint request is currently being handled.

  | 
| [wp_should_load_separate_core_block_assets()](https://developer.wordpress.org/reference/functions/wp_should_load_separate_core_block_assets/)`wp-includes/script-loader.php` |

Checks whether separate styles should be loaded for core blocks.

  | 
| [is_feed()](https://developer.wordpress.org/reference/functions/is_feed/)`wp-includes/query.php` |

Determines whether the query is for a feed.

  | 
| [is_admin()](https://developer.wordpress.org/reference/functions/is_admin/)`wp-includes/load.php` |

Determines whether the current request is for an administrative interface page.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#)

| Used by | Description | 
| [wp_load_classic_theme_block_styles_on_demand()](https://developer.wordpress.org/reference/functions/wp_load_classic_theme_block_styles_on_demand/)`wp-includes/script-loader.php` |

Adds hooks to load block styles on demand in classic themes.

  | 
| [wp_add_global_styles_for_blocks()](https://developer.wordpress.org/reference/functions/wp_add_global_styles_for_blocks/)`wp-includes/global-styles-and-settings.php` |

Adds global style rules to the inline style for each block.

  | 
| [wp_enqueue_block_style()](https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/)`wp-includes/script-loader.php` |

Enqueues a stylesheet for a specific block.

  | 
| [wp_enqueue_global_styles()](https://developer.wordpress.org/reference/functions/wp_enqueue_global_styles/)`wp-includes/script-loader.php` |

Enqueues the global styles defined via theme.json.

  | 
| [enqueue_block_styles_assets()](https://developer.wordpress.org/reference/functions/enqueue_block_styles_assets/)`wp-includes/script-loader.php` |

Function responsible for enqueuing the styles required for block styles functionality on the editor and on the frontend.

  | 
| [wp_enqueue_registered_block_scripts_and_styles()](https://developer.wordpress.org/reference/functions/wp_enqueue_registered_block_scripts_and_styles/)`wp-includes/script-loader.php` |

Enqueues registered block scripts and styles, depending on current rendered context (only enqueuing editor scripts while in context of the editor).

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_should_load_block_assets_on_demand/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.8.0](https://developer.wordpress.org/reference/since/6.8.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_should_load_block_assets_on_demand%2F)
before being able to contribute a note or feedback.