Last active
April 3, 2023 07:21
-
-
Save kwcjr/b85537b02d70eefe3a070a93c2b3b715 to your computer and use it in GitHub Desktop.
Redirect user if not logged in.
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
/** | |
* Snippet Action: Redirect user if not logged in. | |
* Snippet Author: Keith Crain ( MainWP.com ) | |
*/ | |
function custom_template_redirect_fn() | |
{ | |
if( ! is_user_logged_in ) { | |
{ | |
$loginUrl = wp_login_url(); | |
wp_redirect( $loginUrl ); | |
exit(); | |
} | |
} | |
add_action( 'template_redirect', 'custom_template_redirect_fn' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment