Please make sure to update to WPML 4.3.5 and check our list of Known Issues before reporting

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

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 thread is resolved. Here is a description of the problem and solution.

Problem: lowercase forced on hreflang output

Solution:We have a filter called "wpml_hreflangs" that will manipulate the "hrefs langs" in an array. You can find the filter located in /sitepress-multilingual-cms/classes/seo/class-wpml-seoheadlangs.php

[it is not recommended to change anything directly within WPML's code, instead please create a filter and add it to your theme's functions.php file]

To get you started i have test the following filter and it works as expected, just add it to your theme's functions.php and fill in the $code_to_remove and $code_to_add attributes with the correct information

function custom_lang_code($hreflang_items){ $code_to_remove = 'es'; $code_to_add = 'es_ES';

if (array_key_exists($code_to_remove, $hreflang_items)) { $hreflang_items[$code_to_add] = $hreflang_items[$code_to_remove]; unset($hreflang_items[$code_to_remove]); }

return $hreflang_items; } add_filter('wpml_hreflangs', 'custom_lang_code', 10, 1);

Relevant Documentation:

This topic contains 3 replies, has 2 voices.

Last updated by Pieter 6 months, 2 weeks ago.

Assigned support staff: Bobby.

Author Posts
May 29, 2019 at 10:23 am #3914167

Pieter

I am trying to change the notation of the hreflang.

Although WPML says that it needs to be all lowercase divided by a hyphen, there are other sources that say it should be [lowercase hypen capitals]; see screenshot: hidden link

So in the Edit Languages screen, I have changed the notation of the hreflang of the languages accordingly; screenshot: hidden link

However on the frontend nothing changes; screenshot: hidden link

More research shows that also an underscore is changed into a hyphen.

It is nice that WPML is keen on getting SEO right, but wouldn't it be better if users are free to use if they decide to believe other resources?

How can we make it so that lowercase (and hyphen) is/are not forced on us?

Thanks

May 29, 2019 at 4:22 pm #3917327

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-08:00)

Hello,

We have a filter called "wpml_hreflangs" that will manipulate the "hrefs langs" in an array.
You can find the filter located in /sitepress-multilingual-cms/classes/seo/class-wpml-seoheadlangs.php

[it is not recommended to change anything directly within WPML's code, instead please create a filter and add it to your theme's functions.php file]

To get you started i have test the following filter and it works as expected, just add it to your theme's functions.php and fill in the $code_to_remove and $code_to_add attributes with the correct information

function custom_lang_code($hreflang_items){
    $code_to_remove = 'es';
    $code_to_add = 'es_ES';
       
    if (array_key_exists($code_to_remove, $hreflang_items)) {
        $hreflang_items[$code_to_add] = $hreflang_items[$code_to_remove];
        unset($hreflang_items[$code_to_remove]);
    }
 
    return $hreflang_items;
    }
add_filter('wpml_hreflangs', 'custom_lang_code', 10, 1);

NOTE : we cannot provide custom work within the forum the above is a simple example to help you get started, it works as expected as i have test it but we cannot provide any further customization.

May 29, 2019 at 5:18 pm #3917691

Pieter

Hi Bobby,
Many thanks for pointing me to the filter, that is very helpful!
Pieter

May 29, 2019 at 5:19 pm #3917695

Pieter

My issue is resolved now. Thank you!