あくまで自分用の覚え書きなので文章とか適当です...

2026/02/28追記

各言語で異なるfont familyを読み込む

フロント

enqueue-script.php

function my_scripts() {

	// inc/setup.phpにも記述すること
	$locale = get_locale();

	switch ( $locale ) {

		case 'zh_CN': // 中国語(簡体)
			$font_url = 'https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;600&family=Mukta+Vaani:wght@400;600&display=swap';
			break;

		case 'zh_TW': // 中国語(繁体)
			$font_url = 'https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;600&family=Mukta+Vaani:wght@400;600&display=swap';
			break;

		case 'ko_KR': // 韓国語
			$font_url = 'https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;600&family=Mukta+Vaani:wght@400;600&display=swap';
			break;

		default: // 英語(デフォルト)
			$font_url = 'https://fonts.googleapis.com/css2?family=Mukta+Vaani:wght@400;600&display=swap';
			break;
	}

	wp_enqueue_style(
		'google-fonts',
		$font_url,
		array(),
		null
	);

...
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );

css

// 英語
html:lang(en) body {
    font-family: "Mukta Vaani", sans-serif;
}

// 中国語(簡体)
html:lang(zh-CN) body {
    font-family: "Noto Sans SC", sans-serif;
}

// 中国語(繁体)
html:lang(zh-TW) body {
    font-family: "Noto Sans TC", sans-serif;
}

// 韓国語
html:lang(ko-KR) body {
    font-family: "Noto Sans KR", sans-serif;
}

編集画面

add_action(
	'enqueue_block_editor_assets',
	function () {
		// Polylangがないなら何もしない
		if ( ! function_exists( 'pll_get_post_language' ) || ! function_exists( 'pll_current_language' ) ) {
			return;
		}

		$post_id = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : 0;

		// locale 決定(投稿 > 現在言語)
		$locale = pll_get_post_language( $post_id, 'locale' );

		if ( ! $locale ) {
			$locale = pll_current_language( 'locale' );
		}

		// デバッグ(テスト用)
		// wp_add_inline_script( 'wp-blocks', 'console.log("editor locale:", ' . json_encode( $locale ) . ');' );

		$font_url    = '';
		$font_family = '';

		switch ( $locale ) {

			case 'zh_CN': // 中国語(簡体)
				$font_url    = 'https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;600&display=swap';
				$font_family = '"Noto Sans SC", sans-serif';
				break;

			case 'zh_TW': // 中国語(繁体)
				$font_url    = 'https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;600&display=swap';
				$font_family = '"Noto Sans TC", sans-serif';
				break;

			case 'ko_KR': // 韓国語
				$font_url    = 'https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;600&display=swap';
				$font_family = '"Noto Sans KR", sans-serif';
				break;

			default: // 英語(デフォルト)
				$font_url    = 'https://fonts.googleapis.com/css2?family=Mukta+Vaani:wght@400;600&display=swap';
				$font_family = '"Mukta Vaani", sans-serif';
				break;
		}

		if ( $font_url ) {
			wp_enqueue_style( 'my-editor-font', $font_url, array(), null );
		}

		if ( $font_family ) {
			wp_add_inline_style(
				'my-editor-font',
				".editor-styles-wrapper,
				 .editor-styles-wrapper :where(.wp-block-paragraph,.wp-block-heading,.editor-post-title__input,.block-editor-block-list__block){
					font-family: {$font_family} !important;
				}"
			);
		}
	},
	100
);

英語トップページのパーマリンクを ドメイン/en/ にする

英語や他の言語のトップページhttps://example.com/en/ のようにするには [言語] > [設定] > [URLの修正] で「フロントページの URL には、ページ名やページ ID の代わりに言語コードが含まれています」にチェックを入れる

Polylang 各言語のトップページのパーマリンク設定
<?php
	pll_the_languages(
	array(
	'dropdown'      => 1,
	'hide_if_empty' => 0,
	)
	);
?>

<select name="lang_choice_1" id="lang_choice_1" class="pll-switcher-select">
<option value="/en/">English</option>
<option value="/" selected="selected">日本語</option>

</select>
<script type="text/javascript">
document.getElementById("lang_choice_1").addEventListener("change", function(event) {
	location.href = event.currentTarget.value;
})
</script>

注意事項

Custom Post Type Permalinks を使用する場合の例

カスタムタクソノミーの場合の設定

register_taxonomy(
	'products_cat',
	'products',
	array(
		'labels'       => array( 'name' => '製品カテゴリー' ),
		'hierarchical' => true, // カテゴリー.
		'rewrite'      => array(
			'slug'       => 'products-category',
			'with_front' => false,
		),
		'show_in_rest' => true, // Gutenberg.
	)
);

‘slug’ を ‘products/category’ にすると 404 になるので注意

スポンサーリンク

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

WooCommerce対応 ネットショップ向けWordPressテーマ「Japacart ジャパカート」日本語に対応