Filters whether block styles should be loaded separately.
Description
Returning false loads all core block assets, regardless of whether they are rendered in a page or not. Returning true loads core block assets only when they are rendered.
Parameters
$load_separate_assets
bool- Whether separate assets will be loaded.
Default false (all block assets are loaded, even when not used).
Source
return apply_filters( 'should_load_separate_core_block_assets', false );
Changelog
Version | Description |
---|---|
5.8.0 | Introduced. |
Also whilst the default value of this filter is
false
it actually gets changed totrue
by default for any block theme.Since v6.4 you need to add a priority of 11 for this filter to work if you are trying to force block themes to load all block styles rather than just those which WordPress detects are being used …
This hook is poorly named: when returning `true` with this hook; many 3rd-party blocks’ assets (JS and CSS) will only load when those blocks are being used on a page; slightly speeding up your website.
To use:
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
it only needs to be added once for each instance of WordPress you are working with; you do not need to add for each block or plugin that you wish to conditionally load.It should be noted that using this hook will then load inline styles in the body of the website and not the head, which will invalidate your website on W3C validator.