As I tried several different approaches, I think I have to go for the basic way.
I running a multilingual Wordpress website with this domain structure:
example.com
example.co.uk
de.example.com
es.example.com
I have a custom post type e.g.:"members" that I want to translate for SEO purposes to each language. Each post single is translated via strings translations. As I'm using polylang plugin I tried to receive the locale and write a rewrite filter for each locale but that doesn´t work out pretty well. It´s always only one slug working and on all other terms, I receive a 404 for the single posts.
add_filter('register_post_type_args', 'translate_slugs', 10, 2);
function translate_slugs($args, $post_type){
if ($post_type == 'members'){
if (pll_current_language() == "de") {
$args['rewrite']['slug'] = 'mitglied';
};
if (pll_current_language() == "fr") {
$args['rewrite']['slug'] = 'membre';
};
if (pll_current_language() == "es") {
$args['rewrite']['slug'] = 'afiliado';
};
}
return $args;
}
As that doesn´t work out pretty well, I thought about simply adding a rule in the htaccess. But I´m not sure how to do this. Does anyone have an idea on that? I thought about to make the custom post type reachable through all translated slugs and simply add a no-index tag to the duplicates to prevent duplicate content.
I already search for and found some other approaches here, but nothing worked out. I can´t believe I´m the only one facing this problem.