Skip to content

Instantly share code, notes, and snippets.

@webdados
Created January 6, 2020 13:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdados/55728b5e9a5969157f488febf11bc493 to your computer and use it in GitHub Desktop.
Save webdados/55728b5e9a5969157f488febf11bc493 to your computer and use it in GitHub Desktop.
Poor guy's Private WordPress Website - Redirect a user to the login form if he's not logged in
<?php
add_action( 'template_redirect', 'redirect_if_not_logged_in' );
function redirect_if_not_logged_in() {
if ( ! is_user_logged_in() ) wp_redirect( wp_login_url( $_SERVER['REQUEST_URI'] ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment