Title: WP_Font_Library::register_font_collection
Published: April 3, 2024
Last modified: May 20, 2026

---

# WP_Font_Library::register_font_collection( string $slug, array $args ): 󠀁[WP_Font_Collection](https://developer.wordpress.org/reference/classes/wp_font_collection/)󠁿|󠀁[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)󠁿

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#wp--skip-link--target)

Register a new font collection.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#parameters)󠁿

 `$slug`stringrequired

Font collection slug. May only contain alphanumeric characters, dashes, and underscores.
See [sanitize_title()](https://developer.wordpress.org/reference/functions/sanitize_title/).

`$args`arrayrequired

Font collection data. See [wp_register_font_collection()](https://developer.wordpress.org/reference/functions/wp_register_font_collection/)
for information on accepted arguments.

More Arguments from wp_register_font_collection( … $args )

Font collection data.

 * `name` string
 * Required. Name of the font collection shown in the Font Library.
 * `description` string
 * Optional. A short descriptive summary of the font collection. Default empty.
 * `font_families` array|string
 * Required. Array of font family definitions that are in the collection, or a string
   containing the path or URL to a JSON file containing the font collection.
 * `categories` array
 * Optional. Array of categories, each with a name and slug, that are used by the
   fonts in the collection. Default empty.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#return)󠁿

 [WP_Font_Collection](https://developer.wordpress.org/reference/classes/wp_font_collection/)
|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) A font 
collection if it was registered successfully, or [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
object on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#source)󠁿

    ```php
    public function register_font_collection( string $slug, array $args ) {
    	$new_collection = new WP_Font_Collection( $slug, $args );

    	if ( $this->is_collection_registered( $new_collection->slug ) ) {
    		$error_message = sprintf(
    			/* translators: %s: Font collection slug. */
    			__( 'Font collection with slug: "%s" is already registered.' ),
    			$new_collection->slug
    		);
    		_doing_it_wrong(
    			__METHOD__,
    			$error_message,
    			'6.5.0'
    		);
    		return new WP_Error( 'font_collection_registration_error', $error_message );
    	}
    	$this->collections[ $new_collection->slug ] = $new_collection;
    	return $new_collection;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/fonts/class-wp-font-library.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/fonts/class-wp-font-library.php#L46)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/fonts/class-wp-font-library.php#L46-L64)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Font_Library::is_collection_registered()](https://developer.wordpress.org/reference/classes/wp_font_library/is_collection_registered/)`wp-includes/fonts/class-wp-font-library.php` |

Checks if a font collection is registered.

  | 
| [WP_Font_Collection::__construct()](https://developer.wordpress.org/reference/classes/wp_font_collection/__construct/)`wp-includes/fonts/class-wp-font-collection.php` |

[WP_Font_Collection](https://developer.wordpress.org/reference/classes/wp_font_collection/) constructor.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [_doing_it_wrong()](https://developer.wordpress.org/reference/functions/_doing_it_wrong/)`wp-includes/functions.php` |

Marks something as being incorrectly called.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 3 more](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_font_library/register_font_collection/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.5.0](https://developer.wordpress.org/reference/since/6.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_font_library%2Fregister_font_collection%2F)
before being able to contribute a note or feedback.