admin管理员组文章数量:1122832
My WordPress blog is set up as nl_NL
. This means that my bookly plugin is also displayed in nl_NL
.
In the Plugin directory there is a folder languages with loads of other languages.
I have one page in three different languages nl_NL
, de_DE
, en_EN
, on this page I would like the booking plugin to be displayed in the correct language.
I changed the page language via page id from nl_NL
to de_DE
Via the function.php
, but this had no effect.
function get_top_parent_page_id() {
global $post;
if ($post->ancestors) {
return end($post->ancestors);
} else {
return $post->ID;
}
}
function addLangMetaTag (){
$postLanguage = "nl_NL";
if (is_page()) {
$svPageID = get_top_parent_page_id(); // ID of parent page
if ($svPageID == "13040") { // ID of the "på svenska" page
$postLanguage = "de_DE";
}
echo "<meta http-equiv=\"content-language\" content=\"" . $postLanguage . "\">";
}
}
add_filter( 'wp_head', 'addLangMetaTag' );
function language_tagger_change_html_lang_tag() {
return "dir=\"ltr\" lang=\"" .
language_tagger_determin_lang_tag() . "\"";
}
function language_tagger_determin_lang_tag() {
$postLanguage = 'nl_NL'; // default language
if (is_page()) {
$svPageID = get_top_parent_page_id(); // ID of parent page
if ($svPageID == "13040") { // ID of the "på svenska" page
$postLanguage = "de_DE";
}
}
return $postLanguage;
}
add_filter('language_attributes',
'language_tagger_change_html_lang_tag');
I think it will only look at the WordPress config.php
define('WPLANG', 'nl_NL');
I have also been reading this post maybe I could combine something?
My WordPress blog is set up as nl_NL
. This means that my bookly plugin is also displayed in nl_NL
.
In the Plugin directory there is a folder languages with loads of other languages.
I have one page in three different languages nl_NL
, de_DE
, en_EN
, on this page I would like the booking plugin to be displayed in the correct language.
I changed the page language via page id from nl_NL
to de_DE
Via the function.php
, but this had no effect.
function get_top_parent_page_id() {
global $post;
if ($post->ancestors) {
return end($post->ancestors);
} else {
return $post->ID;
}
}
function addLangMetaTag (){
$postLanguage = "nl_NL";
if (is_page()) {
$svPageID = get_top_parent_page_id(); // ID of parent page
if ($svPageID == "13040") { // ID of the "på svenska" page
$postLanguage = "de_DE";
}
echo "<meta http-equiv=\"content-language\" content=\"" . $postLanguage . "\">";
}
}
add_filter( 'wp_head', 'addLangMetaTag' );
function language_tagger_change_html_lang_tag() {
return "dir=\"ltr\" lang=\"" .
language_tagger_determin_lang_tag() . "\"";
}
function language_tagger_determin_lang_tag() {
$postLanguage = 'nl_NL'; // default language
if (is_page()) {
$svPageID = get_top_parent_page_id(); // ID of parent page
if ($svPageID == "13040") { // ID of the "på svenska" page
$postLanguage = "de_DE";
}
}
return $postLanguage;
}
add_filter('language_attributes',
'language_tagger_change_html_lang_tag');
I think it will only look at the WordPress config.php
define('WPLANG', 'nl_NL');
I have also been reading this post maybe I could combine something?
2 Answers
Reset to default 0A simple way to solve this is to use the "Ceceppa Multilingua" plugin. https://wordpress.org/plugins/ceceppa-multilingua/screenshots/
What you're doing is changing the http-equiv meta tag. Changing the HTML tags doesn't change the language of the page content. It just tells browsers (and bots/spiders) what language the content is supposed to be.
If you want to change the language the content is displayed in, you need to change the textdomain for your bookly plugin.
You can do that with WP's plugin_locale
filter. That filter runs when the language files are being loaded and it allows you to change the textdomain (de_DE or nl_NL) that is used.
add_filter( 'plugin_locale', function( $locale ) {
if (is_page()) {
$svPageID = get_top_parent_page_id(); // ID of parent page
if ($svPageID == "13040") { // ID of the "på svenska" page
$locale = "de_DE";
}
}
return $locale;
});
If you need to change more than just the plugin's output (i.e. the language of the entire page), then you probably determine_locale
filter in the determine_locale()
function. It would be the same as above, but with determine_locale
as the filter hook.
本文标签: How do I change a plugin language of only one page
版权声明:本文标题:How do I change a plugin language of only one page? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736295121a1929502.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论