Home Page Redirection for Logged In Users

Hello!

I hope you are doing great!

Yesterday Tyler helped me with a snipped of code to redirect someone from the homepage if they are logged in. My idea is to, like WPMU DEV does, redirect a user to a different page if they are signed up.

function switch_homepage() {
if( is_user_logged_in() ) {
$page = get_page_by_title( 'Sitios');
update_option( 'page_on_front', $page->ID );
update_option( 'show_on_front', 'page' );
}else {
$page = get_page_by_title( 'About' );
update_option( 'page_on_front', $page->ID );
update_option( 'show_on_front', 'page' );
}
}
add_action( 'init', 'switch_homepage' );

His code, as he said, will create two different homepages. The effect is very similar. For a normal user, this will work correctly. The effect is good. The problem is that wrodpress will set up the “logged in homepage” as default, so that would be the page that google sees.

I would like to tweak this code a little in order to make it a redirection, instead than a change. Similar to when you are logged in a visit https://premium.wpmudev.org/ and get redirected automatically to https://premium.wpmudev.org/profile/private/

Could you help me with this?