Skip to content

Instantly share code, notes, and snippets.

@khleomix
Last active February 16, 2022 20:31
Show Gist options
  • Save khleomix/9615cd65cbe6bc26c94cede2d3d9582d to your computer and use it in GitHub Desktop.
Save khleomix/9615cd65cbe6bc26c94cede2d3d9582d to your computer and use it in GitHub Desktop.
ACF Custom Block Category
<?php
/**
* Adds a Custom Block category to the Gutenberg category list.
* Use in acf_register_block_type ( [ 'category' => 'custom-blocks' ] ).
*
* @param array $categories The existing categories.
* @param object $post The current post.
* @return array The updated array of categories.
* @author JC Palmes
*/
function acf_blocks_add_block_categories( $categories, $post ) {
return array_merge(
$categories,
array(
array(
'slug' => 'custom-blocks',
'title' => esc_html__( 'Custom Blocks', 'theme' ),
),
)
);
}
add_filter( 'block_categories_all', 'acf_blocks_add_block_categories', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment