Last active
August 29, 2015 14:02
-
-
Save ShinichiNishikawa/4e94aa284c182127dd83 to your computer and use it in GitHub Desktop.
Add locale to body_class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add locale such as locale_ja, locale_en_US to body class | |
add_filter( 'body_class', 'add_body_class_locale' ); | |
function add_body_class_locale( $classes ) { | |
$classes[] = 'locale_' . sanitize_html_class( get_bloginfo('language') ); | |
return $classes; | |
} |
なるほど!
修正中の発見シェア。
以下のようにしてみたら、locale_en-USが返された!
add_filter( 'body_class', 'add_body_class_locale' ); function add_body_class_locale( $classes ) { $locale = get_bloginfo('language') ? get_bloginfo('language') : 'none'; $classes[] = 'locale_' . $locale; return $classes; }
元の状態って残るの?
add_filter( 'body_class', 'add_body_class_locale' ); function add_body_class_locale( $classes ) { $classes[] = 'locale_' . WPLANG; return $classes; }
sanitize_html_class
修正しました!!
sanitize_html_class 知らなかった!
return sanitize_html_class ($classes);
のほうがよくね?
もしくは
$classes[] = sanitize_html_class( 'locale_' . get_bloginfo('language') );
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
あと
get_bloginfo('language')
でも language とれます。シングルインストールでBogoの様なプラグインを津亜kったばあいは未検証です。