I creating website and I need to have different homepages for logged in and logged off users. I have page 'Home page' which is set as home page and is filled with information about my site and pictures and simple page 'Home logged in' which was set as BuddyPress activity stream. What I need is: - User A is visiting website but he is not logged in and can see 'Home page' as homepage - User B is visiting website and he is logged in and can see 'Home page logged in' as homepage. I have tried to reach it with this code, by inserting it to my theme functions.php :
function switch_homepage() {
if ( is_user_logged_in() ) {
$page = get_page_by_title( 'Home page logged in' );
update_option( 'page_on_front', $page->ID );
update_option( 'show_on_front', 'page' );
} else {
$page = get_page_by_title( 'Home page' );
update_option( 'page_on_front', $page->ID );
update_option( 'show_on_front', 'page' );
}
}
add_action( 'init', 'switch_homepage' );
But this code sometimes when refreshing page or logging off started to show 'Home page logged in' for logged off users. As I readed this happening because this code change homepage in database. So now my question is how to have separate home page for logged off users without changing database every time?