функция since 6.4.0

wp_print_font_faces()

Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.

Сигнатура

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

Описание

Генерирует и выводит стили font-face для указанных шрифтов или шрифтов из theme.json.

Параметры

$fonts array[][] необязательный = array()
The font-families and their font faces.
  • ...$0 array An indexed or associative (keyed by font-family) array of font variations for this font-family.
    Each font face has the following structure.
    • ...$0 array The font face properties.
      • font-family stringThe font-family property.
      • src string|string[]The URL(s) to each resource containing the font data.
      • font-style stringOptional. The font-style property. Default 'normal'.
      • font-weight stringOptional. The font-weight property. Default '400'.
      • font-display stringOptional. The font-display property. Default 'fallback'.
      • ascent-override stringOptional. The ascent-override property.
      • descent-override stringOptional. The descent-override property.
      • font-stretch stringOptional. The font-stretch property.
      • font-variant stringOptional. The font-variant property.
      • font-feature-settings stringOptional. The font-feature-settings property.
      • font-variation-settings stringOptional. The font-variation-settings property.
      • line-gap-override stringOptional. The line-gap-override property.
      • size-adjust stringOptional. The size-adjust property.
      • unicode-range stringOptional. 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 );
      }
      

      View all references View on Trac View on GitHub

      Related
      UsesDescription
      WP_Font_Face_Resolver::get_fonts_from_theme_json()wp-includes/fonts/class-wp-font-face-resolver.php

      Gets fonts defined in theme.json.

      WP_Font_Face::generate_and_print()wp-includes/fonts/class-wp-font-face.php

      Generates and prints the @font-face styles for the given fonts.

      Used byDescription
      wp_print_font_faces_from_style_variations()wp-includes/fonts.php

      Generates and prints font-face styles defined the the theme style variations.

      _wp_get_iframed_editor_assets()wp-includes/block-editor.php

      Collect the block editor assets that need to be loaded into the editor’s iframe.

      Changelog
      VersionDescription
      6.4.0Introduced.
      User Contributed Notes
      1. Skip to note 2 content Rodrigo Vieira Eufrasio da Silva 3 years ago You must log in to vote on the helpfulness of this noteVote results for this note: -1You must log in to vote on the helpfulness of this note
        $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 );
        Log in to add feedback

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

Исходный код

wp-includes/fonts.php:43

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 );
}

История изменений

ВерсияОписание
6.4.0 Introduced.

Что будем искать? Например,Продвижение

Этот сайт использует куки-файлы. Оставаясь на сайте, Вы соглашаетесь на их использование. Для получения дополнительной информации, пожалуйста, ознакомьтесь с политикой в отношении персональных данных.