Created
November 6, 2019 19:15
-
-
Save zorzv/79d888e3d0c6b78d9c07575765fb9eb9 to your computer and use it in GitHub Desktop.
Redirect Logged Out Users To Homepag
This file contains 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
/** | |
* Redirect Logged Out Users To Homepage | |
* | |
* @uses template_redirect() Template Redirect action hook | |
* @uses is_user_logged_in() conditional tag | |
* @uses is_page() conditional tag | |
* @uses is_front_page() conditional tag | |
* @uses wp_redirect() WP Redirect function | |
* | |
*/ | |
function redirect_to_homepage() { | |
if ( !is_user_logged_in() && !is_page( 'login' ) && ! is_page('register') && ! is_front_page() ) { | |
//redirect logged out users to homepage | |
wp_redirect( home_url() ); | |
exit; | |
} | |
add_action('template_redirect', 'redirect_to_homepage'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment