是的,有点像。任何本地化插件(如WP Members)都会脱离WordPress设置的“语言环境”。可以使用locale
滤器但也可以使用plugin_locale
请参见:https://developer.wordpress.org/reference/hooks/plugin_locale/
使用plugin_locale
特定于插件*的文本域(在本例中为“wp members”)
add_filter( \'plugin_locale\', \'my_plugin_locale_filter\', 10, 2 );
function my_plugin_locale_filter( $locale, $domain ) {
// If the text domain is \'wp-members\'
if ( \'wp-members\' == $domain ) {
/*
* This logic adapted from the method you referenced at
* http://beta.beantin.se/wordpress-setting-language-individual-pages/
* Note that the function get_top_parent_page_id() from that example
* is used here, and the logic is not adapted to your specific
* question (i.e. I assume the default $postLanguage value is
* Norwegian in your case and you are switching it to English) so
* change this to match what you are doing with the other elements
* being used from that process.
*/
$postLanguage = "en-GB";
if (is_page()) {
$svPageID = get_top_parent_page_id(); // ID of parent page
if ($svPageID == "565") { // ID of the "på svenska" page
$postLanguage = "sv";
}
$locale = $postLanguage;
}
}
// Always return the value being filtered.
return $locale;
}
*任何插件的文本域都应在插件主文件的标题中注明。例如,如果打开wp成员。php并查看插件标题,您将在标题“文本域:”下找到它。