Skip to content

Instantly share code, notes, and snippets.

@jrtashjian
Last active September 22, 2023 22:28
Show Gist options
  • Save jrtashjian/6a7c16ec5d9fd60ca39a546d58b626ae to your computer and use it in GitHub Desktop.
Save jrtashjian/6a7c16ec5d9fd60ca39a546d58b626ae to your computer and use it in GitHub Desktop.
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