register_block_type

函式
register_block_type ( $block_type, $args = array() )
引數
  • (string|WP_Block_Type) $block_type Block type name including namespace, or alternatively a path to the JSON file with metadata definition for the block, or a path to the folder where the `block.json` file is located, or a complete WP_Block_Type instance. In case a WP_Block_Type is provided, the $args parameter will be ignored.
    Required:
  • (array) $args Optional. Array of block type arguments. Accepts any public property of `WP_Block_Type`. See WP_Block_Type::__construct() for information on accepted arguments. Default empty array.
    Required:
    Default: array()
返回值
  • (WP_Block_Type|false) The registered block type on success, or false on failure.
定義位置
相關方法
unregister_block_typeregister_block_styleunregister_block_styleregister_post_typeregister_block_style_handle
引入
5.0.0
棄用
-

register_block_type: 這個函式用來為WordPress的塊編輯器註冊一個新的塊型別。它需要兩個引數:$name和$args。$name是一個定義塊型別名稱的字串,而$args是一個定義塊的行為和外觀的選項陣列: 這個函式應該在”init”動作鉤子中呼叫。

註冊一個塊型別。推薦的方法是使用儲存在 `block.json` 檔案中的後設資料來註冊一個塊型別。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function register_block_type( $block_type, $args = array() ) {
if ( is_string( $block_type ) && file_exists( $block_type ) ) {
return register_block_type_from_metadata( $block_type, $args );
}
return WP_Block_Type_Registry::get_instance()->register( $block_type, $args );
}
function register_block_type( $block_type, $args = array() ) { if ( is_string( $block_type ) && file_exists( $block_type ) ) { return register_block_type_from_metadata( $block_type, $args ); } return WP_Block_Type_Registry::get_instance()->register( $block_type, $args ); }
function register_block_type( $block_type, $args = array() ) {
	if ( is_string( $block_type ) && file_exists( $block_type ) ) {
		return register_block_type_from_metadata( $block_type, $args );
	}

	return WP_Block_Type_Registry::get_instance()->register( $block_type, $args );
}

常見問題

FAQs
檢視更多 >