0

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');

为什么?

4

0 回答 0