Created
May 15, 2023 09:56
-
-
Save raftaar1191/4699bd600f92ebd38621813f671c537e to your computer and use it in GitHub Desktop.
Change homepage for the login and non-login user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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