should_load_separate_core_block_assets

Home » Hooks » should_load_separate_core_block_assets

WordPress introduced the Gutenberg editor in version 5.0, which was a big change in the way content is created and edited in WordPress. The Gutenberg editor uses blocks to structure content, which led to the creation of the block editor, a new way to create content in WordPress.

The should_load_separate_core_block_assets hook was introduced in WordPress 5.0 to allow developers to control whether or not the core block assets should be loaded separately or not.

By default, WordPress loads the core block assets separately, which means that it loads the JavaScript and CSS files required for the block editor to function properly as separate files rather than including them in the main WordPress files. This can help improve the performance of your website by reducing the amount of data that needs to be loaded on each page.

However, there may be situations where you want to load the core block assets inline with the rest of your website’s assets. In this case, you can use the should_load_separate_core_block_assets hook to disable the separate loading of these assets.

Here is an example of how you can use the should_load_separate_core_block_assets filter to disable the separate loading of the core block assets:

function my_disable_block_assets_loading( $should_load_separate ) {
    return false;
}
add_filter( 'should_load_separate_core_block_assets', 'my_disable_block_assets_loading' );

In this example, we have created a function called my_disable_block_assets_loading that simply returns false. We then use the add_filter function to attach this function to the should_load_separate_core_block_assets hook. This will disable the separate loading of the core block assets, causing them to be loaded inline with the rest of your website’s assets.

Note that this filter should only be used if you have a good reason to do so, as it may have an impact on the performance of your website.

Learn More on WordPress.org

WordPress snippets using the should_load_separate_core_block_assets hook

Register an account to save your snippets or go Pro to get more features.