Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello @sacconi

    To transform links dynamically from Italian to German or English, you can use a custom function in your theme’s functions.php file. This code automatically detects the Italian short links and redirects them to the corresponding German or English URLs:

    add_action('template_redirect', function() {$url = $_SERVER['REQUEST_URI'];if (strpos($url, '/?p=') !== false) {$post_id = url_to_postid($url);$lang_prefix = (strpos($_SERVER['HTTP_HOST'], 'de') !== false) ? 'de' : 'en';$translated_url = get_permalink($post_id);if ($lang_prefix) {$translated_url = str_replace('sacconicase.com', "$lang_prefix.sacconicase.com", $translated_url);wp_redirect($translated_url, 301);exit;}}});

    Alternatively, a plugin like Polylang or WPML can help manage multilingual links, enabling easy URL switching between languages

    Thread Starter sacconi

    (@sacconi)

    I dont need an automatic redirect, I have to choose case by case when using a language or another, i.e, if I’m writing to a german customer I’ll send the links to the pages in german. So I would need a selector to change the language

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.