函数文档

_wp_register_default_font_collections()

💡 云策文档标注

概述

_wp_register_default_font_collections() 函数用于注册 WordPress 的默认字体集合,具体通过 wp_register_font_collection() 注册 Google Fonts 集合,包含字体名称、描述、字体家族 URL 和分类信息。

关键要点

  • 函数 _wp_register_default_font_collections() 在 WordPress 6.5.0 版本引入,用于注册默认字体集合。
  • 它调用 wp_register_font_collection() 注册一个名为 'google-fonts' 的字体集合,参数包括本地化名称、描述、字体数据 URL 和分类数组。
  • 分类数组定义了五种字体类别:Sans Serif、Display、Serif、Handwriting 和 Monospace,每个类别有名称和 slug。
  • 函数使用 _x() 和 __() 进行字符串本地化,确保多语言支持。

代码示例

function _wp_register_default_font_collections() {
	wp_register_font_collection(
		'google-fonts',
		array(
			'name'          => _x( 'Google Fonts', 'font collection name' ),
			'description'   => __( 'Install from Google Fonts. Fonts are copied to and served from your site.' ),
			'font_families' => 'https://s.w.org/images/fonts/wp-6.9/collections/google-fonts-with-preview.json',
			'categories'    => array(
				array(
					'name' => _x( 'Sans Serif', 'font category' ),
					'slug' => 'sans-serif',
				),
				array(
					'name' => _x( 'Display', 'font category' ),
					'slug' => 'display',
				),
				array(
					'name' => _x( 'Serif', 'font category' ),
					'slug' => 'serif',
				),
				array(
					'name' => _x( 'Handwriting', 'font category' ),
					'slug' => 'handwriting',
				),
				array(
					'name' => _x( 'Monospace', 'font category' ),
					'slug' => 'monospace',
				),
			),
		)
	);
}

📄 原文内容

Register the default font collections.

Source

function _wp_register_default_font_collections() {
	wp_register_font_collection(
		'google-fonts',
		array(
			'name'          => _x( 'Google Fonts', 'font collection name' ),
			'description'   => __( 'Install from Google Fonts. Fonts are copied to and served from your site.' ),
			'font_families' => 'https://s.w.org/images/fonts/wp-6.9/collections/google-fonts-with-preview.json',
			'categories'    => array(
				array(
					'name' => _x( 'Sans Serif', 'font category' ),
					'slug' => 'sans-serif',
				),
				array(
					'name' => _x( 'Display', 'font category' ),
					'slug' => 'display',
				),
				array(
					'name' => _x( 'Serif', 'font category' ),
					'slug' => 'serif',
				),
				array(
					'name' => _x( 'Handwriting', 'font category' ),
					'slug' => 'handwriting',
				),
				array(
					'name' => _x( 'Monospace', 'font category' ),
					'slug' => 'monospace',
				),
			),
		)
	);
}

Changelog

Version Description
6.5.0 Introduced.