Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:

The client installed WordPress in German (Sie) and then WPML, which switched to German (Du). In the meta tags, 'german-formal' appears, which the client believes is not good for SEO. They need to tag the website as being in German while using formal German with WPML.

Solution:

We recommend adding a function to the theme's child functions.php file to modify the HTML language attribute for German. Here is the code you should use:

add_filter('language_attributes', 'modify_language_attributes_for_german');

function modify_language_attributes_for_german($lang) {
    // Check if the current language is German
    $my_current_lang = apply_filters( 'wpml_current_language', NULL );
    if ($my_current_lang === 'de') {
        // Replace the language code for German
        return 'lang="de-DE"';
    }
    return $lang; // Keep default language attributes for other languages
}

If this solution does not resolve your issue, or if it seems outdated or irrelevant to your case, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please open a new support ticket at WPML support forum.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 3 replies, has 0 voices.

Last updated by philippeB-68 1 week ago.

Assisted by: Shekhar Bhandari.

Author Posts
December 6, 2024 at 5:25 pm #16487014

philippeB-68

Background of the issue:
I have installed WordPress with the German (Sie) language and then installed WPML. It switches to German (Du). I understand that I can change this, but in the meta tags, I get 'german-formal'.

Symptoms:
The meta tags show 'german-formal', which I believe is not good for SEO.

Questions:
How do I tag my website as being in German while still using formal German with WPML?

December 9, 2024 at 4:27 am #16490882

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

Thank you for contacting WPML support. I'd be happy to assist you on this issue.

To help you further on this issue, I would need further information, so could you please go to WPML > Support > Debug Information and give me the information in the next reply. You can read the detailed instruction here: http://wpml.org/faq/provide-debug-information-faster-support/

What happens when you deactivate the WPML plugins, does the meta tags shows properly? Can you share me the screenshot?

Look forward to your reply.

Thanks

December 10, 2024 at 2:59 pm #16499040

philippeB-68

Hello,

Thanks for coming back. I believe that this is due to how I have to configure WPML to ensure that I have the formal version of the German language. According to what I read in the forum, I have to enter "de_DE_formal" in the default locale, but then in the HTML code I have <html lang="de-DE-formal">, which is not standard.

Thanks
Philippe

Screenshot 2024-12-10 at 15.57.49.png
December 11, 2024 at 4:56 am #16501362

Shekhar Bhandari
Supporter

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

If you want the language attributes to show de-de for german, then you can use the following functions, you can add this to your theme child functions.php file.

add_filter('language_attributes', 'modify_language_attributes_for_german');
function modify_language_attributes_for_german($lang) {
    // Check if the current language is German
	$my_current_lang = apply_filters( 'wpml_current_language', NULL );
    if ($my_current_lang === 'de') {
        // Replace the language code for German
        return 'lang="de-DE"';
    }
    return $lang; // Keep default language attributes for other languages
}

Let me know if this helps.

Thanks

December 12, 2024 at 11:18 am #16507372

philippeB-68

Thank you, this solved my issue !
Best regards,
Philippe