Skip to content

Instantly share code, notes, and snippets.

@ControlledChaos
Last active June 1, 2019 15:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ControlledChaos/5cb56ed9e5b77851ac2288e7286e33fb to your computer and use it in GitHub Desktop.
Save ControlledChaos/5cb56ed9e5b77851ac2288e7286e33fb to your computer and use it in GitHub Desktop.
Show reusable blocks in the admin menu.

Show Reusable Blocks in the Admin Menu

WordPress Snippet

<?php
/**
* Show reusable blocks in the admin menu
*
* Filters the wp_block post type arguments.
*
* @param array $args The registered post type arguments.
* @param string $post_type The post type slug.
* @return array Returns the filtered array of arguments.
*/
function show_blocks_in_menu( $args, $post_type ) {
// Bail if not the wp_block post type.
if ( 'wp_block' !== $post_type ) {
return $args;
}
// Clearly label the blocks as reusable.
$wp_block_labels = [
'name' => __( 'Reusable Blocks', 'text-domain' ),
'menu_name' => __( 'Blocks', 'text-domain' ),
'all_items' => __( 'Reusable Blocks', 'text-domain' ),
'search_items' => __( 'Search Blocks', 'text-domain' )
];
// New block arguments.
$wp_block_args = [
'_builtin' => false,
'show_in_menu' => true,
'menu_position' => 63,
'menu_icon' => 'dashicons-screenoptions',
'labels' => $wp_block_labels
];
// Merge and return the filtered array of arguments.
return array_merge( $args, $wp_block_args );
}
// Add the filter.
add_filter( 'register_post_type_args', 'show_blocks_in_menu', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment