wp_print_font_faces( array[][] $fonts = array() )

Generates and prints font-face styles for given fonts or theme.json fonts.

Parameters

$fontsarray[][]optional
The font-families and their font variations.
  • font-family string
    => array[] $variations { Optional. An associated array of font variations for this font-family.
    Each variation has the following structure.
  • font_variation array
    • font-family string
      The font-family property.
    • src string|string[]
      The URL(s) to each resource containing the font data.
    • font_style string
      Optional. The font-style property. Default 'normal'.
    • font-weight string
      Optional. The font-weight property. Default '400'.
    • font-display string
      Optional. The font-display property. Default 'fallback'.
    • ascent-override string
      Optional. The ascent-override property.
    • descent-override string
      Optional. The descent-override property.
    • font-stretch string
      Optional. The font-stretch property.
    • font-variant string
      Optional. The font-variant property.
    • font-feature-settings string
      Optional. The font-feature-settings property.
    • font-variation-settings string
      Optional. The font-variation-settings property.
    • line-gap-override string
      Optional. The line-gap-override property.
    • size-adjust string
      Optional. The size-adjust property.
    • unicode-range string
      Optional. The unicode-range property.
      }

Default:array()

Source

function wp_print_font_faces( $fonts = array() ) {

	if ( empty( $fonts ) ) {
		$fonts = WP_Font_Face_Resolver::get_fonts_from_theme_json();
	}

	if ( empty( $fonts ) ) {
		return;
	}

	$wp_font_face = new WP_Font_Face();
	$wp_font_face->generate_and_print( $fonts );
}

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

  1. Skip to note 2 content
    $fonts = array(
        'font-family-1' => array(
            'variations' => array(
                'font-variation-1' => array(
                    'font-family' => 'Font Family 1',
                    'src' => array(
                        'url-to-font-variation-1.woff',
                        'url-to-font-variation-1.woff2',
                    ),
                    'font-style' => 'italic',
                    'font-weight' => '700',
                    // Other optional properties...
                ),
                // Add more variations if necessary...
            ),
        ),
        'font-family-2' => array(
            'variations' => array(
                'font-variation-2' => array(
                    'font-family' => 'Font Family 2',
                    'src' => array(
                        'url-to-font-variation-2.woff',
                        'url-to-font-variation-2.woff2',
                    ),
                    // Outras propriedades opcionais...
                ),
                // Add more variations if necessary...
            ),
        ),
        // Add more font families if necessary...
    );
    
    wp_print_font_faces( $fonts );

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