add_action->switch_to_locale
通过工程更改语言环境,而add_filter
不能。
添加过滤器
function change_locale( $locale ) {
if (is_singular()) {
global $post;
if(($post->ID=='1839') || ($post->ID=='577') || ($post->ID=='1346')){
$locale = 'en_US';
}
}
return $locale;
}
add_filter('locale', 'change_locale');
add_action
function change_to_english_local() {
if (is_singular()) {
global $post;
if(($post->ID=='1839') || ($post->ID=='577') || ($post->ID=='1346')){
switch_to_locale('en_US');
}
}
}
add_action( 'wp_enqueue_scripts', 'change_to_english_local');
为什么?