wp_should_load_separate_core_block_assets

函式
wp_should_load_separate_core_block_assets ( No parameters )
返回值
  • (bool) Whether separate assets will be loaded.
相關
  • wp_enqueue_registered_block_scripts_and_styles()
  • register_block_style_handle()
定義位置
相關方法
_load_remote_block_patternswp_should_upgrade_global_tableswp_should_load_block_editor_scripts_and_stylesbuild_template_part_block_variationswp_should_replace_insecure_home_url
引入
5.8.0
棄用
-

wp_should_load_separate_core_block_assets是一個函式,用於確定在WordPress塊編輯器(Gutenberg)中是否應該單獨載入核心塊資產(JavaScript和CSS)。

檢查是否應該在渲染時為核心區塊載入單獨的樣式。

當這個函式返回”true”時,其他函式會確保核心區塊只在render時載入它們的資產,而每個區塊則載入它自己的獨立資產。第三方塊只在渲染時載入它們的資產。

當此函式返回false時,所有的核心區塊資產都會被載入,不管它們是否在頁面中被渲染,因為它們都是`block-library/style.css`檔案的一部分。第三方塊的資產總是被排隊,不管它們是否被渲染。

這隻影響到前端,而不是區塊編輯器螢幕。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >