Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list and re-arrange or manipulate Gutenberg Block Categories in Wordpress

Anyone know how to re-arrange, manipulate the Block Categories in the Gutenberg Editor in Wordpress I can't even return a list of them as you can with the Blocks themselves, all I can find is 'getCategories' which doesn't seem do anything... the new documentation is not great at all.

like image 302
Paul Jackson Avatar asked Jan 14 '19 16:01

Paul Jackson


People also ask

How do I manage blocks in WordPress?

To manage your blocks, click on the add block button and then locate the Reusables tab. You'll see a link to manage your reusable blocks page. Clicking on the link will bring you to block management page. From here, you can edit, delete, export, and import your blocks.

How do I group Gutenberg blocks?

Group block with columns, heading, paragraph, image and button blocks. To add a group block, click on the Block Inserter icon. You can also type /group and hit enter in a new paragraph block to add one quickly.


1 Answers

This did the trick for me to register a custom Guttenberg block and make it the first option in WP Admin editor:

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);
like image 167
ecairol Avatar answered Sep 20 '22 02:09

ecairol