wordpresswpml

WPML same slug(url) different language


I have this site :

example.com/watches (watches is a custom post type)

There are two available languages : EN(default language), GR.

When i change to GR (while on page example.com/watches) it redirects to example.com/el/watches which is right.

When i am on example.com/watches/rolex and i try to change language it redirects to example.com/el/taxwatches/rolex-el but i want it just to be example.com/el/watches/rolex/.

taxwatches is my custom taxonomy.

rolex-el is the slug of the term inside that taxonomy.

Has anyone experienced an issue like this before?

I've tried to save the permalinks again and check my WMPL settings but i can't see something wrong.

EDIT 1 : If i manually go to example.com/el/watches/rolex it will work fine. Both example.com/el/watches/rolex and example.com/el/taxwatches/rolex-el work.

EDIT 2: From what i understand WPML takes the slugs, is there a way to change it so it takes the names?


Solution

  • Ok so for anyone having problems with multi language sites - but want to have the "same slugs" in the urls (will never be same slugs - but going to look like that) read the below.

    WPML uses slugs which are created from the wordpress core structure - you can't have two slugs with the exactly same name. If default language is EN and you have a secondary, in my case GR, then one slug is going to be "myslug" and the other "myslug-gr" (you can customize this "-gr" through WPML settings).

    In functions.php you can filter the "wpml_ls_filter" function which is fired when your Language switcher is created.

    Code as below :

    add_filter('icl_ls_languages', 'wpml_ls_filter');
    
    function wpml_ls_filter($languages) {
    
       foreach ($languages as $lang_code => $language) {
    
           $mTempString = $languages[$lang_code]['url'];
    
           echo $mTempString; // HERE
    
           // If "tax" is found in that string, replace it with "" - remove it.
           if (strpos($mTempString, "tax") !== false) {
    
                  $languages[$lang_code]['url'] = str_replace("tax", "", $mTempString);
           }
    
       }
    return $languages;
    }
    

    The above echo is going to show you the url that is created (and you can manipulate it) of each language button when pressed whenever you visit a page/post.

    I haven't wrote a complete solution because that really depends on what you want to do. For example the above code helped me achieve to remove "tax" if found in the url.