Skip to content

Instantly share code, notes, and snippets.

@gnikolopoulos
Created August 27, 2015 10:51
Show Gist options
  • Save gnikolopoulos/43d5cf068abb57597ebc to your computer and use it in GitHub Desktop.
Save gnikolopoulos/43d5cf068abb57597ebc to your computer and use it in GitHub Desktop.
[Wordpress] Different homepage for logged in users
<?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' );
?>
@kwakueffa
Copy link

Hello there, I started a little research on how to change the homepage for users once they are either logged in or logged out just as this code does.

but it looks like 'switch_homepage' effects the database itself everytime. so it causes confusion when two users acces the site and one is logged in and one is logged out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment