0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Bogoのlanguage switcherの表示テキストを変更する

Posted at

フィルターフックで書き換え

functions.phpに

functions.php
add_filter( 'bogo_language_switcher_links','bogo_override_labels');
function bogo_override_labels($output){
	foreach($output as $key => $value){
		if($value['lang'] === 'en-US'){
			$output[$key]['title'] = 'EN';
			$output[$key]['native_name'] = 'EN';
		}
		else if($value['lang'] === 'ja'){
			$output[$key]['title'] = 'JP';
			$output[$key]['native_name'] = 'JP';
		}
	}
 return $output;
}

$value['lang']の値で振り分けてラベル表示用のtitleとnative_nameを上書きする。

titleはタイトル属性としてとnative_nameがない場合のラベルテキストとして利用されている様子。
https://github.com/wp-plugins/bogo/blob/master/includes/link-template.php

過去の反省

css
.bogo-language-switcher .en-US a{
 font-size: 0;
}
.bogo-language-switcher .en-US a:after{
 content: 'EN';
 font-size: 14px;
}

みたいな対応もできるんですが、昔その対応したサイトに国旗が表示されるようになっていたのを見て考え直しました。

なお国旗については
https://joppot.info/2017/03/29/3657
こちらのサイト参考に消しました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?