Created
November 6, 2019 19:19
-
-
Save zorzv/ba0626ae0f3b2b418f381c569366b6b3 to your computer and use it in GitHub Desktop.
Redirect Non-Members to Login Page
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 Visitors To Login Page | |
* | |
* @author Zo Rizvi | |
* | |
* @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 | |
* @uses auth_redirect() Auth Redirect function | |
* | |
* | |
*/ | |
function redirect_to_login() { | |
if ( !is_user_logged_in() && !is_page( 'login' ) && ! is_page('register') && ! is_front_page() ) { | |
//redirect non-logged in members to Login Page | |
wp_redirect( auth_redirect() ); | |
exit; | |
} | |
add_action('template_redirect', 'redirect_to_login'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment