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" 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/alt-home" page, it redirects me to "mywebsite". I would like the page to be able to be viewed in its custom URL.
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" 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/alt-home" page, it redirects me to "mywebsite". I would like the page to be able to be viewed in its custom URL.
Share Improve this question asked Oct 23, 2020 at 9:50 AncientRoAncientRo 3663 silver badges12 bronze badges 2 |1 Answer
Reset to default 0I 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.
the_content
filter? Or in your template, use a conditional to display the alternative home page's content.. – Sally CJ Commented Oct 23, 2020 at 16:15