WP_Font_Face::order_src( array $font_face ): array

In this article

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.

Orders src items to optimize for browser support.

Parameters

$font_facearrayrequired
Font face to process.

Return

array Font-face with ordered src items.

Source

private function order_src( array $font_face ) {
	if ( ! is_array( $font_face['src'] ) ) {
		$font_face['src'] = (array) $font_face['src'];
	}

	$src         = array();
	$src_ordered = array();

	foreach ( $font_face['src'] as $url ) {
		// Add data URIs first.
		if ( str_starts_with( trim( $url ), 'data:' ) ) {
			$src_ordered[] = array(
				'url'    => $url,
				'format' => 'data',
			);
			continue;
		}
		$format         = pathinfo( $url, PATHINFO_EXTENSION );
		$src[ $format ] = $url;
	}

	// Add woff2.
	if ( ! empty( $src['woff2'] ) ) {
		$src_ordered[] = array(
			'url'    => $src['woff2'],
			'format' => 'woff2',
		);
	}

	// Add woff.
	if ( ! empty( $src['woff'] ) ) {
		$src_ordered[] = array(
			'url'    => $src['woff'],
			'format' => 'woff',
		);
	}

	// Add ttf.
	if ( ! empty( $src['ttf'] ) ) {
		$src_ordered[] = array(
			'url'    => $src['ttf'],
			'format' => 'truetype',
		);
	}

	// Add eot.
	if ( ! empty( $src['eot'] ) ) {
		$src_ordered[] = array(
			'url'    => $src['eot'],
			'format' => 'embedded-opentype',
		);
	}

	// Add otf.
	if ( ! empty( $src['otf'] ) ) {
		$src_ordered[] = array(
			'url'    => $src['otf'],
			'format' => 'opentype',
		);
	}
	$font_face['src'] = $src_ordered;

	return $font_face;
}

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

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