任何人都知道如何在Wordpress的Gutenberg编辑器中重新排列,操作块类别,我什至无法像使用块本身一样返回它们的列表,我所能找到的只是“ getCategories”,而没有似乎什么也没做...新的文档一点也不好。
答案 0 :(得分:2)
这使我成功注册了一个自定义的Guttenberg块,并使它成为WP Admin编辑器中的第一个选项:
function custom_block_category( $categories ) {
$custom_block = array(
'slug' => 'my-blocks',
'title' => __( 'My Test Blocks', 'my-blocks' ),
);
$categories_sorted = array();
$categories_sorted[0] = $custom_block;
foreach ($categories as $category) {
$categories_sorted[] = $category;
}
return $categories_sorted;
}
add_filter( 'block_categories', 'custom_block_category', 10, 2);
答案 1 :(得分:0)
这是一个较短的解决方案:
function custom_block_category( $categories ) {
return array_merge(
array(
array(
'slug' => 'my-blocks',
'title' => __( 'My Test Blocks', 'my-blocks' ),
),
),
$categories
);
}
add_filter( 'block_categories', 'custom_block_category', 10, 2 );