inc2734/wp-google-fonts

0.5.1 2022-07-08 04:40 UTC

This package is auto-updated.

Last update: 2024-11-08 09:53:07 UTC


README

CI Latest Stable Version License

When a user with customize permission enqueues a font, the font is downloaded from the Google Fonts API. It then references the downloaded font. Fonts files are stored in wp-content/uploads/inc2734-wp-google-fonts.

Install

$ composer require inc2734/wp-google-fonts

How to use

<?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' ] );

Filter hooks

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

Third-party resources

Noto Sans Japanese

Noto Serif Japanese

M PLUS 1p

M PLUS Rounded 1c

BIZ UDPGothic

BIZ UDPMincho