• Resolved fdetourneint

    (@fdetourneint)


    Hello,

    I have a problem when I put the same URI for 1 same page in several languages.
    I use WPML.

    For example, for a site in french by default :
    in French: uri = paris.html -> domain.com/paris.html
    in English : uri = paris.html -> domain.com/en/paris.html
    in German : uri = paris.html -> domain.com/de/paris.html

    But only page in english displayed and the others show a 404 error.

    When I change for english page to paris-en.html and german page to paris-de.html, it works but I want same URI.

    Do you know what the problem would be?

    Thank you,
    FD

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @fdetourneint,

    Could you check if “WPML/Polylang language mismatch” option is turned on in Permalink Manager settings?

    Best regards,
    Maciej

    Thread Starter fdetourneint

    (@fdetourneint)

    Hi Maciej,

    I had seen this on a Polylang forum but for WPML I couldn’t find it. In fact it was the same setting. It’s working fine now!!

    Thank you very much !

    FD

    Thread Starter fdetourneint

    (@fdetourneint)

    Hi Maciej,

    I have another problem when I turn on “WPML/Polylang language mismatch” option.
    For example, I have a page with different language :
    – in FR : domain.com/la-region
    – in EN : domain.com/en/the-region
    – in NL : domain.com/nl/de-region

    When WMPL option turn on, if I test this url : domain.com/en/la-region, I have 304 http code with html in english but i have no redirection to domain.com/en/the-region.

    How can I have a redirection 301 to domain.com/en/the-region for this example ?

    Thanks,
    FD

    Plugin Author Maciej Bis

    (@mbis)

    Hi @fdetourneint,

    Unfortunately this is not possible with the plugin itself at this moment. However, you can try to use the below code snippet to check the language mismatch:

    function pm_fix_language_mismatch($item_id, $uri_parts, $is_term = false) {
    	if(!$is_term) {
    		$element = get_post($item_id);
    
    		if(!empty($element->post_type)) {
    			$element_id = $item_id;
    			$element_type = $element->post_type;
    		}
    	}
    
    	// Stop if no term or post is detected
    	if(empty($element)) { return false; }
    
    	// Get the language code of the found post/term
    	$element_language_code = Permalink_Manager_Language_Plugins::get_language_code($element);
    
    	// Get the detected language code
    	if(defined('ICL_LANGUAGE_CODE')) {
    		$detected_language_code = ICL_LANGUAGE_CODE;
    	} else if(!empty($uri_parts['lang'])) {
    		$detected_language_code = $uri_parts['lang'];
    	} else {
    		return $item_id;
    	}
    
    	if($detected_language_code !== $element_language_code) {
    		$item_id = apply_filters('wpml_object_id', $element_id, $element_type);
    
    		if(!empty($item_id)) {
    			$canonical_permalink = get_permalink($item_id);
    
    			wp_safe_redirect($canonical_permalink, 301);
    			exit();
    		}
    	}
    
    	return $item_id;
    }
    add_filter('permalink_manager_detected_post_id', 'pm_fix_language_mismatch', 7, 3);
    Thread Starter fdetourneint

    (@fdetourneint)

    Hi Maciej,

    Thank you for your code, it works.

    FD

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘permalink manager + wpml + same URI’ is closed to new replies.