wp_register_icon_collection()WP 7.1.0

Registers a new SVG icon collection.

A collection groups related icons and serves as a namespace. For example, the collection for the my-plugin/star icon is my-plugin.

Register the collection before calling wp_register_icon(). It is recommended to do this on the init action.

No Hooks.

Returns

bool.

  • true - the collection was successfully registered.
  • false - invalid arguments were provided or a collection with the same slug already exists. WordPress also generates an _doing_it_wrong() notice.

Usage

wp_register_icon_collection( $slug, $args );
$slug(string) (required)

Unique collection slug.

It must begin and end with a lowercase Latin letter or a digit. Lowercase Latin letters, digits, hyphens, and underscores are allowed inside it.

For example: my-plugin, theme_icons, icons2.

$args(array) (required)

Collection arguments. Unknown keys cause registration to fail.

  • label(string) (required)
    Human-readable collection name. It is displayed in the icon picker interface.

  • description(string)
    Collection description.
    Default: ''

Examples

#1 Registering a plugin icon collection

add_action( 'init', 'my_plugin_register_icon_collection' );

function my_plugin_register_icon_collection() {
	wp_register_icon_collection(
		'my-plugin',
		[
			'label'       => __( 'My Plugin Icons', 'my-plugin' ),
			'description' => __( 'Icons provided by My Plugin.', 'my-plugin' ),
		]
	);
}

Changelog

Since 7.1.0 Introduced.

wp_register_icon_collection() code WP 7.1

function wp_register_icon_collection( $slug, $args ) {
	return WP_Icon_Collections_Registry::get_instance()->register( $slug, $args );
}