wp_should_load_separate_core_block_assets() WordPress Function

The wp_should_load_separate_core_block_assets() function is used to determine whether separate assets should be loaded for the block editor and the front-end of the site. This can be useful for debugging or performance reasons.

wp_should_load_separate_core_block_assets() #

Checks whether separate styles should be loaded for core blocks on-render.


Description

When this function returns true, other functions ensure that core blocks only load their assets on-render, and each block loads its own, individual assets. Third-party blocks only load their assets when rendered.

When this function returns false, all core block assets are loaded regardless of whether they are rendered in a page or not, because they are all part of the block-library/style.css file. Assets for third-party blocks are always enqueued regardless of whether they are rendered or not.

This only affects front end and not the block editor screens.

Top ↑

See also


Top ↑

Return

(bool) Whether separate assets will be loaded.


Top ↑

Source

File: wp-includes/script-loader.php

function wp_should_load_separate_core_block_assets() {
	if ( is_admin() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
		return false;
	}

	/**
	 * 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.
	 *
	 * @since 5.8.0
	 *
	 * @param bool $load_separate_assets Whether separate assets will be loaded.
	 *                                   Default false (all block assets are loaded, even when not used).
	 */
	return apply_filters( 'should_load_separate_core_block_assets', false );
}


Top ↑

Changelog

Changelog
VersionDescription
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.