skip to Main Content

I need to set it by the technical task.
I’ve found only

function hrefs_to_uppercase($hrefs) {  
    $hrefs = array_change_key_case($hrefs,CASE_UPPER);
    return $hrefs;
}
add_filter( 'wpml_hreflangs', 'hrefs_to_uppercase' );

But it makes all characters uppercase – "EN-AE".
Tried manually in wpml settings- didn’t help

2

Answers


  1. Chosen as BEST ANSWER

    I solved like that for now, maybe right-maybe not

         jQuery('[hreflang*="en-ae"]').each(function(){
            // Update the 'rules[0]' part of the name attribute to contain the latest count 
            jQuery(this).attr("hreflang",'en-AE');
        });  
    

  2. You can simply replace the array key with the following code:

    function hrefs_to_uppercase($hrefs) {  
        $hrefs['en-AE'] = $hrefs['en-ae'];
        unset($hrefs['en-ae']);
        return $hrefs;
    }
    add_filter( 'wpml_hreflangs', 'hrefs_to_uppercase' );
    

    if you want to make every array key have an uppercase second part (e.g. from en-us to en-US), you can use the codes below (assumed all your keys have a similar structure like en-us):

    function hrefs_to_uppercase($hrefs) {  
        foreach ($hrefs as $key => $val) {
            $key_tokens = explode('-', $key);
            $new_key = $key_tokens[0] . '-' . strtoupper($key_tokens[1]);
            $hrefs[$new_key] = $hrefs[$key];
            unset($hrefs[$key]);
        }
        return $hrefs;
    }
    add_filter( 'wpml_hreflangs', 'hrefs_to_uppercase' );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search