Skip to content

Instantly share code, notes, and snippets.

@raftaar1191
Created May 15, 2023 09:56
Show Gist options
  • Save raftaar1191/4699bd600f92ebd38621813f671c537e to your computer and use it in GitHub Desktop.
Save raftaar1191/4699bd600f92ebd38621813f671c537e to your computer and use it in GitHub Desktop.
Change homepage for the login and non-login user
/**
* Add condition to check if the user is login and non-login
* Notes: Make sure to set the login user homepage as the default homepage in the Admin Dashboard -> Settings-> Reading
*/
function change_the_homepage_for_non_login_user() {
if ( ! is_admin() && ! is_user_logged_in() ) {
add_filter( 'pre_option_page_on_front', 'pre_option_page_on_front_homepage_for_non_login_user' );
}
}
add_action( 'init', 'change_the_homepage_for_non_login_user' );
/**
* Home page id for the non login user
*/
function pre_option_page_on_front_homepage_for_non_login_user() {
return 50;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment