WP_Font_Utils::sanitize_font_family( string $font_family ): string

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use sanitize_text_field() instead.

Sanitizes and formats font family names.

Description

  • Applies sanitize_text_field.
  • Adds surrounding quotes to names containing any characters that are not alphabetic or dashes.

It follows the recommendations from the CSS Fonts Module Level 4.

See also

Parameters

$font_familystringrequired
Font family name(s), comma-separated.

Return

string Sanitized and formatted font family name(s).

Source

public static function sanitize_font_family( $font_family ) {
	if ( ! $font_family ) {
		return '';
	}

	$output          = sanitize_text_field( $font_family );
	$formatted_items = array();
	if ( str_contains( $output, ',' ) ) {
		$items = explode( ',', $output );
		foreach ( $items as $item ) {
			$formatted_item = self::maybe_add_quotes( $item );
			if ( ! empty( $formatted_item ) ) {
				$formatted_items[] = $formatted_item;
			}
		}
		return implode( ', ', $formatted_items );
	}
	return self::maybe_add_quotes( $output );
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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