diff --git a/ming-theme/assets/css/fonts.css b/ming-theme/assets/css/fonts.css index fe3c677..6ffb67f 100644 --- a/ming-theme/assets/css/fonts.css +++ b/ming-theme/assets/css/fonts.css @@ -1,5 +1,6 @@ -/* MING 明命 — 自托管字体(v1.5.6 起替代 Google Fonts 外链) - 来源:google/fonts(OFL 授权),经子集化(Big5 常用字 + 全形标点)与字重实例化 */ +/* MING 明命 — 自托管字體(v1.5.6 起替代 Google Fonts 外鏈) + 繁體中文站點使用下列 TC 字型;其他站點語言由主題選用對應系統字型。 + 來源:google/fonts(OFL 授權),經子集化(Big5 常用字 + 全形標點)與字重實例化。 */ @font-face { font-family: 'Cormorant Garamond'; diff --git a/ming-theme/assets/css/main.css b/ming-theme/assets/css/main.css index ff815d3..2b4a10b 100644 --- a/ming-theme/assets/css/main.css +++ b/ming-theme/assets/css/main.css @@ -8,9 +8,10 @@ --ink:#2B2B26; --muted:#7A756A; --line:rgba(43,43,38,.16); - --serif:'Noto Serif TC',serif; - --latin:'Cormorant Garamond','Noto Serif TC',serif; - --sans:'Noto Sans TC',sans-serif; + /* WordPress 依站點語言於前台覆寫下列字型堆疊。 */ + --serif:Georgia,'Times New Roman',serif; + --latin:'Cormorant Garamond',Georgia,'Times New Roman',serif; + --sans:system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif; } *{margin:0;padding:0;box-sizing:border-box} html{scroll-behavior:smooth} diff --git a/ming-theme/footer.php b/ming-theme/footer.php index 5126a92..1b2d852 100644 --- a/ming-theme/footer.php +++ b/ming-theme/footer.php @@ -39,7 +39,7 @@ $ming_mailto = $ming_email ? $ming_email : 'hello@ming.example'; - LINE + LINE diff --git a/ming-theme/functions.php b/ming-theme/functions.php index 8bda0be..996bd36 100644 --- a/ming-theme/functions.php +++ b/ming-theme/functions.php @@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -define( 'MING_VERSION', '1.7.3' ); +define( 'MING_VERSION', '1.7.4' ); /** * Theme setup. @@ -52,6 +52,66 @@ function ming_setup() { } add_action( 'after_setup_theme', 'ming_setup' ); +/** + * Return the site's WordPress locale in a form suitable for comparisons. + * + * @return string + */ +function ming_site_locale() { + return strtolower( str_replace( '-', '_', get_locale() ) ); +} + +/** + * Build font stacks for the language selected in WordPress settings. + * + * Self-hosted TC font files are used for Traditional Chinese. Other site + * languages use the appropriate platform font stack and do not request a + * Chinese Traditional web font. + * + * @return string CSS custom-property declarations. + */ +function ming_font_stack_css() { + $locale = ming_site_locale(); + $fonts = array( + 'sans' => "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif", + 'serif' => "Georgia, 'Times New Roman', serif", + 'latin' => "'Cormorant Garamond', Georgia, 'Times New Roman', serif", + ); + + if ( preg_match( '/^zh_(?:hant(?:_|$)|tw(?:_|$)|hk(?:_|$)|mo(?:_|$))/', $locale ) ) { + $fonts = array( + 'sans' => "'Noto Sans TC', 'Noto Sans CJK TC', 'PingFang TC', 'Microsoft JhengHei', 'Heiti TC', sans-serif", + 'serif' => "'Noto Serif TC', 'Noto Serif CJK TC', 'Songti TC', 'PMingLiU', 'MingLiU', serif", + 'latin' => "'Cormorant Garamond', 'Noto Serif TC', 'Noto Serif CJK TC', 'Songti TC', serif", + ); + } elseif ( preg_match( '/^zh_/', $locale ) ) { + $fonts = array( + 'sans' => "'Noto Sans SC', 'Noto Sans CJK SC', 'PingFang SC', 'Microsoft YaHei', 'Heiti SC', sans-serif", + 'serif' => "'Noto Serif SC', 'Noto Serif CJK SC', 'Songti SC', SimSun, serif", + 'latin' => "'Cormorant Garamond', 'Noto Serif SC', 'Noto Serif CJK SC', 'Songti SC', serif", + ); + } elseif ( preg_match( '/^ja(?:_|$)/', $locale ) ) { + $fonts = array( + 'sans' => "'Noto Sans JP', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', Meiryo, sans-serif", + 'serif' => "'Noto Serif JP', 'Hiragino Mincho ProN', 'Yu Mincho', serif", + 'latin' => "'Cormorant Garamond', 'Noto Serif JP', 'Hiragino Mincho ProN', serif", + ); + } elseif ( preg_match( '/^ko(?:_|$)/', $locale ) ) { + $fonts = array( + 'sans' => "'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif", + 'serif' => "'Noto Serif KR', AppleMyungjo, Batang, serif", + 'latin' => "'Cormorant Garamond', 'Noto Serif KR', AppleMyungjo, serif", + ); + } + + return sprintf( + ":root {\n\t--serif: %1\$s;\n\t--latin: %2\$s;\n\t--sans: %3\$s;\n}\n", + $fonts['serif'], + $fonts['latin'], + $fonts['sans'] + ); +} + /** * Enqueue assets. */ @@ -65,6 +125,7 @@ function ming_assets() { ); wp_enqueue_style( 'ming-main', get_template_directory_uri() . '/assets/css/main.css', array( 'ming-fonts' ), MING_VERSION ); + wp_add_inline_style( 'ming-main', ming_font_stack_css() ); wp_enqueue_script( 'ming-main', get_template_directory_uri() . '/assets/js/main.js', array(), MING_VERSION, true ); // Pass image directory to JS (product grid). @@ -739,6 +800,57 @@ add_action( 'after_switch_theme', 'ming_seed_footer_content' ); * ==========================================================*/ /* ---------- OG / Twitter 分享標籤 ---------- */ +/** + * Return an Open Graph locale derived from the WordPress site language. + * + * @return string + */ +function ming_og_locale() { + $locale = ming_site_locale(); + + if ( 0 === strpos( $locale, 'zh_' ) ) { + if ( preg_match( '/(?:hk)/', $locale ) ) { + return 'zh_HK'; + } + if ( preg_match( '/(?:mo)/', $locale ) ) { + return 'zh_MO'; + } + + return preg_match( '/(?:hant|tw)/', $locale ) ? 'zh_TW' : 'zh_CN'; + } + + $parts = explode( '_', $locale ); + $language = isset( $parts[0] ) ? $parts[0] : 'en'; + $region = ''; + foreach ( array_reverse( $parts ) as $part ) { + if ( 2 === strlen( $part ) && ctype_alpha( $part ) ) { + $region = strtoupper( $part ); + break; + } + } + + if ( $region ) { + return $language . '_' . $region; + } + + $default_regions = array( + 'ar' => 'SA', + 'de' => 'DE', + 'en' => 'US', + 'es' => 'ES', + 'fr' => 'FR', + 'it' => 'IT', + 'ja' => 'JP', + 'ko' => 'KR', + 'nl' => 'NL', + 'pl' => 'PL', + 'pt' => 'BR', + 'ru' => 'RU', + ); + + return isset( $default_regions[ $language ] ) ? $language . '_' . $default_regions[ $language ] : 'en_US'; +} + add_action( 'wp_head', 'ming_og_tags', 5 ); function ming_og_tags() { if ( is_admin() || ( function_exists( 'is_embed' ) && is_embed() ) ) { return; } @@ -784,7 +896,7 @@ function ming_og_tags() { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; - echo '' . "\n"; + echo '' . "\n"; if ( $image ) { echo '' . "\n"; } diff --git a/ming-theme/style.css b/ming-theme/style.css index 060078b..4310f5e 100644 --- a/ming-theme/style.css +++ b/ming-theme/style.css @@ -4,7 +4,7 @@ Theme URI: https://ming.example Author: MING 明命 Author URI: https://ming.example Description: MING 明命品牌官網主題 —— 陶瓷內膽杯 · 明亮生命 自然連結。單頁式品牌首頁,支援 WooCommerce 商城、會員中心、購物車角標、社群連結與公司資訊自訂。 -Version: 1.7.3 +Version: 1.7.4 Requires at least: 6.0 Tested up to: 6.7 Requires PHP: 7.4 diff --git a/ming-theme/template-brand.php b/ming-theme/template-brand.php index 932d6e9..c6ae259 100644 --- a/ming-theme/template-brand.php +++ b/ming-theme/template-brand.php @@ -65,7 +65,7 @@ get_header();

太陽與光

光明溫暖,
希望明亮。

- 明命 + 明命

明・命

生命因光而明,
萬物因自然而生。