How to Dynamically Switch WordPress Front Page Without Causing Canonical Redirect?

I found a solution that worked (though I need to test it thoroughly)

First, add a filter on the “page on front” option:

function filter_page_on_front($default) {
  $current_post_language = detect_post_language();
  if ($current_post_language) {
    $intro_page = get_current_page();
    if ($intro_page) {
      $page_on_front = get_option('page_on_front_' . $current_post_language, '');
      if ($page_on_front && $intro_page->ID == $page_on_front) {
        return $page_on_front;
      }
    }
  }
  return $default;
}

add_filter('pre_option_page_on_front', 'filter_page_on_front');

Next is to disable redirects on the front pages:

function wpdocs_disable_frontpage_canonical_redirect($redirect) {
  
  if (is_front_page()) {
    $redirect = false;
  }

  return $redirect;
}

add_filter('redirect_canonical', 'wpdocs_disable_frontpage_canonical_redirect');

and the last is to return the page slug for that other(s) front page:

function custom_page_link($link, $post_id, $sample) {

  $current_post_language = detect_post_language();
  $main_language = get_option('selected_language', 'en_US');
  if ($current_post_language && $current_post_language != $main_language) {
    $page_on_front = get_db_option('page_on_front_' . $current_post_language, '');
    if ($page_on_front && $post_id == $page_on_front) {
      $page_slug = get_post_field('post_name', $page_on_front); // Get the slug of the page
      if ($page_slug) {
        return home_url("https://wordpress.stackexchange.com/" . $page_slug . "https://wordpress.stackexchange.com/");
      }
    }
  }

  return $link;
}

add_filter('page_link', 'custom_page_link', 10, 3);

Please, note that get_db_option will get unfiltered options.

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino