bool $load_separate_assets )
Filters whether block styles should be loaded separately.
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.
Whether separate assets will be loaded.
Default false (all block assets are loaded, even when not used).
View all references
return apply_filters( 'should_load_separate_core_block_assets', false );
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.
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.
This hook affects only loading of core blocks, not third party blocks, hence the name *_core_block_assets — By Lovro Hrust —
Based on my testing, this is correct – it does affects custom blocks. I have an open track ticket about it, and recently found that this filter was the actual culprit: https://core.trac.wordpress.org/ticket/54956 — By pkostadinov —
Just need to keep in mind one thing – that is when using this filter the styles/assets will get loaded almost at end of the body tag rather than loading in the HEAD tag. Not sure if it’s a bug or intended – but this is how it works. — By Saumya Majumder —
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.