By default, I present the user with the "Home" front page (set in "Settings / Reading / Homepage").

I have a duplicate page of this called "Alt Home", with some changed content.

When the user goes to the front page, if the "use_alt_home" cookie exists (which I set based on certain conditions), I want to show the user the "Alt Home" page instead (not redirect, load the "Alt Home" page at the "mywebsite.com" address, instead of the "Home" page).

I tried the following code:

function use_alt_home_page( $page_id ) {
    $alt_home_id = 105;

    if ( is_admin() ) {
        return $page_id;

    if ( isset( $_COOKIE['alt_home_page'] ) ) {
        return $alt_home_id;

    return $page_id;

add_filter( 'option_page_on_front', 'use_alt_home_page', 20 );

This works on my localhost but when I deploy I get the "ERR_TOO_MANY_REDIRECTS" error.

Is there another way I can code the alternative home page, or using this same method, fix the redirects error?

One other issue is that when I want to go directly to the "mywebsite.com/alt-home" page, it redirects me to "mywebsite.com". I would like the page to be able to be viewed in its custom URL.

  • If it's just the post content that's different, you could just use the the_content filter? Or in your template, use a conditional to display the alternative home page's content..
    – Sally CJ
    Oct 23, 2020 at 16:15
  • That is what I ended up doing. The page uses Advanced Custom Fields and it has tens of "get_field()" functions that retrieve the page data. If the cookie is set, I give the "get_field()" functions the ID of the alternative page, otherwise I let it use the default page ID.
    – AncientRo
    Oct 26, 2020 at 7:51

1 Answer 1


I ended up using a workaround method: In the home page template file, I verify if the cookie is set and if so, I retrieve the data from the alternative page, as opposed to from the current page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.