Skip to content

Instantly share code, notes, and snippets.

@gh640
Created September 5, 2024 04:13
Show Gist options
  • Save gh640/255ea29949d0ea2958571a545b879c0a to your computer and use it in GitHub Desktop.
Save gh640/255ea29949d0ea2958571a545b879c0a to your computer and use it in GitHub Desktop.
WordPress: Font Library でオリジナルのフォントコレクションを追加する
<?php
add_action( 'init', 'themeslug_add_font_collections' );
/**
* フォントコレクションを追加する
*/
function themeslug_add_font_collections() {
// フォントファミリーの定義:
$font_families = [
[
'font_family_settings' => [
'fontFamily' => 'Open Sans, sans-serif',
'slug' => 'open-sans',
'name' => 'Open Sans',
'fontFace' => [
[
'fontFamily' => 'Open Sans',
'fontStyle' => 'normal',
'fontWeight' => '300',
'src' => 'https://fonts.gstatic.com/s/opensans/v40/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsiH0C4iY1M2xLER.woff2',
],
[
'fontFamily' => 'Open Sans',
'fontStyle' => 'italic',
'fontWeight' => '400',
'src' => 'https://fonts.gstatic.com/s/opensans/v40/memQYaGs126MiZpBA-UFUIcVXSCEkx2cmqvXlWq8tWZ0Pw86hd0Rk8ZkaVIUwaERZjA.woff2'
],
],
],
'categories' => [ 'sans-serif' ],
],
[
'font_family_settings' => [
'fontFamily' => 'Monoton, system-ui',
'slug' => 'monoton',
'name' => 'Monoton',
'fontFace' => [
[
'fontFamily' => 'Monoton',
'fontStyle' => 'normal',
'fontWeight' => '400',
'src' => 'https://fonts.gstatic.com/s/monoton/v19/5h1aiZUrOngCibe4fkPBQ2S7FU8.woff2',
'preview' => 'https://s.w.org/images/fonts/17.7/previews/monoton/monoton-400-normal.svg'
],
],
],
'categories' => [ 'display' ],
],
[
'font_family_settings' => [
'fontFamily' => 'Arial, Helvetica, Tahoma, Geneva, sans-serif',
'slug' => 'arial',
'name' => 'Arial',
],
'categories' => [ 'sans-serif' ],
],
];
// フォントカテゴリーの定義:
$categories = [
[
'name' => _x( 'Display', 'Font category name' ),
'slug' => 'display',
],
[
'name' => _x( 'Sans Serif', 'Font category name' ),
'slug' => 'sans-serif',
],
];
$config = [
'name' => '私のフォントコレクション',
'description' => '私が好きなフォントのコレクション。',
'font_families' => $font_families,
'categories' => $categories,
];
// フォントコレクション(フォントファミリーとカテゴリー)を登録する:
wp_register_font_collection ( 'my-font-collection', $config );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment