Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get With Gutenberg - Creating a Block Category • https://getwithgutenberg.com/2019/04/creating-a-block-category/
<?php
/**
* Add a block category for "Get With Gutenberg" if it doesn't exist already.
*
* @param array $categories Array of block categories.
*
* @return array
*/
function gwg_block_categories( $categories ) {
$category_slugs = wp_list_pluck( $categories, 'slug' );
return in_array( 'gwg', $category_slugs, true ) ? $categories : array_merge(
$categories,
array(
array(
'slug' => 'gwg',
'title' => __( 'Get With Gutenberg', 'gwg' ),
'icon' => null,
),
)
);
}
add_filter( 'block_categories', 'gwg_block_categories' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.