get_default_block_categories(): array[]

Returns the list of default categories for block types.

Return

array[] Array of categories for block types.

Source

function get_default_block_categories() {
	return array(
		array(
			'slug'  => 'text',
			'title' => _x( 'Text', 'block category' ),
			'icon'  => null,
		),
		array(
			'slug'  => 'media',
			'title' => _x( 'Media', 'block category' ),
			'icon'  => null,
		),
		array(
			'slug'  => 'design',
			'title' => _x( 'Design', 'block category' ),
			'icon'  => null,
		),
		array(
			'slug'  => 'widgets',
			'title' => _x( 'Widgets', 'block category' ),
			'icon'  => null,
		),
		array(
			'slug'  => 'theme',
			'title' => _x( 'Theme', 'block category' ),
			'icon'  => null,
		),
		array(
			'slug'  => 'embed',
			'title' => _x( 'Embeds', 'block category' ),
			'icon'  => null,
		),
		array(
			'slug'  => 'reusable',
			'title' => _x( 'Patterns', 'block category' ),
			'icon'  => null,
		),
	);
}

Changelog

VersionDescription
6.3.0Reusable Blocks renamed to Patterns.
5.8.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    This code defines a function called get_default_block_categories()that returns an array of default block categories for a block-based content editor, like the one used in WordPress’s Gutenberg editor. Block-based editors allow users to create content by assembling different types of “blocks,” such as text, images, videos, and more. These blocks are categorized to make it easier for users to find and use them. Let’s break down the code step by step:

    The function is defined using the function keyword: function get_default_block_categories() { ... }. This function doesn’t take any arguments and will return an array of block categories.

    Inside the function, an array is defined that holds information about each block category. Each block category is represented as an associative array with three keys: 'slug', 'title', and 'icon'.

    The 'slug' key is a short identifier for the block category. It’s used to uniquely identify and reference the category.
    The ‘title' key holds the display name of the block category. The _x() function is used for localization, allowing the block category name to be translated into different languages.
    The 'icon' key represents the icon associated with the block category. In this code snippet, the value is null, indicating that no specific icon is assigned to these categories.
    The array contains seven block category definitions, each with a unique 'slug', a localized 'title', and a null 'icon'.

    'text': Represents a category for text-related blocks.
    'media': Represents a category for media-related blocks, such as images and videos.
    'design': Represents a category for design-related blocks.
    'widgets': Represents a category for widget-related blocks.
    'theme': Represents a category for blocks related to the overall theme of the content.
    'embed': Represents a category for embed-related blocks, like embedding external content.
    'reusable': Represents a category for reusable pattern blocks.
    After defining all the block categories in the array, the function ends with a closing curly brace: }.

    When this function is called, it will return an array containing these default block categories, which can then be used by a block-based content editor to organize and present different types of content blocks to the user in a structured manner.

You must log in before being able to contribute a note or feedback.