inc2734/wp-google-fonts

0.5.1 2022-07-08 04:40 UTC

This package is auto-updated.

Last update: 2024-09-08 09:25:54 UTC


README

CI Latest Stable Version License

当具有 customize 权限的用户将字体放入队列时,该字体将从 Google Fonts API 下载。然后引用下载的字体。字体文件存储在 wp-content/uploads/inc2734-wp-google-fonts

安装

$ composer require inc2734/wp-google-fonts

如何使用

<?php
new \Inc2734\WP_Google_Fonts\Bootstrap();

// Enqueue Noto Sans JP
add_action( 'wp_enqueue_scripts', [ '\Inc2734\WP_Google_Fonts\Helper', 'enqueue_noto_sans_jp' ], 5 );
add_action( 'enqueue_block_editor_assets', [ '\Inc2734\WP_Google_Fonts\Helper', 'enqueue_noto_sans_jp' ] );

// Noto Serif JP
add_action( 'wp_enqueue_scripts', [ '\Inc2734\WP_Google_Fonts\Helper', 'enqueue_noto_serif_jp' ], 5 );
add_action( 'enqueue_block_editor_assets', [ '\Inc2734\WP_Google_Fonts\Helper', 'enqueue_noto_serif_jp' ] );

过滤器钩子

inc2734_wp_google_fonts_font_weight

/**
 * @param string $weight 400:700
 * @return string
 */
add_filter(
  'inc2734_wp_google_fonts_font_weight',
  function( $weight ) {
    return $weight;
  }
);

inc2734_wp_google_fonts_base_directory

/**
 * @param string $directory WP_CONTENT_DIR
 * @return string
 */
add_filter(
  'inc2734_wp_google_fonts_base_directory',
  function( $directory ) {
    return $directory;
  }
);

inc2734_wp_google_fonts_refresh_font

/**
 * @param boolean $refresh true if you want to force a font file refresh.
 * @param string  $css_full_path Full path of CSS file.
 * @return boolean
 */
add_filter(
  'inc2734_wp_google_fonts_refresh_font',
  function( $refresh, $css_full_path ) {
    return $refresh;
  },
  10,
  2
);

第三方资源

Noto Sans Japanese

Noto Serif Japanese

M PLUS 1p

M PLUS Rounded 1c

BIZ UDPGothic

BIZ UDPMincho