_add_default_theme_supports

函式
_add_default_theme_supports ( No parameters )

_add_default_theme_supports: 這個函式用來給一個WordPress主題新增預設的主題支援。主題支援是一個主題可以宣告它支援的功能,它允許WordPress啟用或禁用特定的功能,這取決於主題是否支援它們。

當’setup_theme’動作觸發時,為區塊主題新增預設主題支援。

參見{@see ‘setup_theme’}。

function _add_default_theme_supports() {
	if ( ! wp_is_block_theme() ) {
		return;
	}

	add_theme_support( 'post-thumbnails' );
	add_theme_support( 'responsive-embeds' );
	add_theme_support( 'editor-styles' );
	/*
	 * Makes block themes support HTML5 by default for the comment block and search form
	 * (which use default template functions) and `` and `` shortcodes.
	 * Other blocks contain their own HTML5 markup.
	 */
	add_theme_support( 'html5', array( 'comment-form', 'comment-list', 'search-form', 'gallery', 'caption', 'style', 'script' ) );
	add_theme_support( 'automatic-feed-links' );

	add_filter( 'should_load_separate_core_block_assets', '__return_true' );

	/*
	 * Remove the Customizer's Menus panel when block theme is active.
	 */
	add_filter(
		'customize_panel_active',
		static function ( $active, WP_Customize_Panel $panel ) {
			if (
				'nav_menus' === $panel->id &&
				! current_theme_supports( 'menus' ) &&
				! current_theme_supports( 'widgets' )
			) {
				$active = false;
			}
			return $active;
		},
		10,
		2
	);
}

常見問題

FAQs
檢視更多 >