W3cubDocs

/WordPress

WP_Font_Face::build_font_face_css( array $font_face ): string

Builds the font-family’s CSS.

Parameters

$font_facearrayrequired
Font face to process.

Return

string This font-family’s CSS.

Source

private function build_font_face_css( array $font_face ) {
	$css = '';

	/*
	 * Wrap font-family in quotes if it contains spaces
	 * and is not already wrapped in quotes.
	 */
	if (
		str_contains( $font_face['font-family'], ' ' ) &&
		! str_contains( $font_face['font-family'], '"' ) &&
		! str_contains( $font_face['font-family'], "'" )
	) {
		$font_face['font-family'] = '"' . $font_face['font-family'] . '"';
	}

	foreach ( $font_face as $key => $value ) {
		// Compile the "src" parameter.
		if ( 'src' === $key ) {
			$value = $this->compile_src( $value );
		}

		// If font-variation-settings is an array, convert it to a string.
		if ( 'font-variation-settings' === $key && is_array( $value ) ) {
			$value = $this->compile_variations( $value );
		}

		if ( ! empty( $value ) ) {
			$css .= "$key:$value;";
		}
	}

	return $css;
}

Changelog

Version Description
6.4.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_font_face/build_font_face_css