Created
April 29, 2024 06:58
-
-
Save Olein-jp/20442aef7499f2adba30da45e4085bb9 to your computer and use it in GitHub Desktop.
ブロックバリエーションを作成してカスタムフィールドを出力するサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function book_introduce_block_type_variations( $variations, $block_type ) { | |
if ( 'core/heading' === $block_type->name ) { | |
$variations[] = array( | |
'name' => 'book-title', | |
'title' => 'Book Title', | |
'attributes' => array( | |
'metadata' => array( | |
'bindings' => array( | |
'content' => array( | |
'source' => 'acf/field', | |
'args' => array( | |
'key' => 'book-title', | |
), | |
), | |
), | |
), | |
), | |
); | |
} elseif ( 'core/image' === $block_type->name ) { | |
$variations[] = array( | |
'name' => 'book-thumbnail', | |
'title' => 'Book Thumbnail', | |
'attributes' => array( | |
'metadata' => array( | |
'bindings' => array( | |
'url' => array( | |
'source' => 'acf/field', | |
'args' => array( | |
'key' => 'book-thumbnail', | |
), | |
), | |
), | |
), | |
), | |
); | |
} elseif ( 'core/button' === $block_type->name ) { | |
$variations[] = array( | |
'name' => 'book-amazon-url', | |
'title' => 'Book Amazon URL', | |
'attributes' => array( | |
'metadata' => array( | |
'bindings' => array( | |
'url' => array( | |
'source' => 'acf/field', | |
'args' => array( | |
'key' => 'book-amazon-url', | |
), | |
), | |
), | |
), | |
), | |
); | |
} | |
return $variations; | |
} | |
add_filter( 'get_block_type_variations', 'book_introduce_block_type_variations', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参照:https://olein-design.com/blog/show-custom-fields-value-by-block-variation