Archived topic
Show different Homepage Content Logged-In User
8 replies · Started by John on September 2, 2020
Hi!
I'm looking for a way to show different home-page/front-page content for a logged-in user/member. Ideas?
Thanks!
John
I tried this in snippets but it didn't work for me.
if( is_user_logged_in() ) {
$page = get_page_by_title( 'page-title');
update_option( 'page_on_front', $page->ID );
update_option( 'show_on_front', 'page' );
}
else {
$page = get_page_by_title( 'page-title' );
update_option( 'page_on_front', $page->ID );
update_option( 'show_on_front', 'page' );
}
Hi there,
this topic may help:
https://generatepress.com/forums/topic/redirect-logged-in-users/#post-1298931
If you read further down Tom also provides a Stack Overflow for redirection upon login.
Thanks, David.
I'm ok with redirecting users after login, what I'm trying to do is this;
-
If a user is logged out and goes to the home page url, they see page A.
If a user is logged in and goes to the home page url, they see page B.
I tried using the following code mentioned by someone else in the thread you referenced (found here, with different page id's) but when activated it changes the static and post pages in DASHBOARD > SETTINGS > READING to the same page. That fouls things up pretty good.
?php
function switch_homepage() {
if ( is_user_logged_in() ) {
$page = 2516; // for logged in users
update_option( 'page_on_front', $page );
update_option( 'show_on_front', 'page' );
} else {
$page = 2; // for logged out users
update_option( 'page_on_front', $page );
update_option( 'show_on_front', 'page' );
}
}
add_action( 'init', 'switch_homepage' );
?>
I would recommend starting a topic on WordPress Stack if the link David provided doesn't solve the issue:
https://wordpress.stackexchange.com/
This isn't a GP related question so we can only provide limited help here.
Thanks for your understanding :)
Will do. Thanks, Leo.
No problem :)
On the off chance that someone else has this same question, here is a link on StackExchange that addresses this issue.
Awesome.
Thanks for sharing!