0

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.

Community
  • 1
  • 1
MCG
  • 503
  • 6
  • 20
  • _"I already search for and found some other approaches here, but nothing worked out."_ - info like that is almost completely useless, because we don't know _what exactly_ you found and tried. So suggesting _anything_ at this point might be a fruitless endeavor to begin with - it might fall under what you already tried without success. Talk about motivating people _not_ to bother with your question any further in the first place ... – 04FS Nov 20 '19 at 13:11
  • In the pro version of the plugin this appears to exist as a built-in feature already, https://polylang.pro/doc/translating-urls-slugs/ And https://github.com/KLicheR/wp-polylang-translate-rewrite-slugs looks to be promising an easy solution to add it yourself (or at least a place where to look further, it uses a hook that apears to be specific to the plugin.) If the latter should fall under what you already tried, then at least give us a proper problem description of how exactly you tried to use it, and in which way it "didn't work" exactly. – 04FS Nov 20 '19 at 13:12

0 Answers0