Skip to content

Instantly share code, notes, and snippets.

@marcbacon
Last active August 29, 2015 14:22
Show Gist options
  • Save marcbacon/b6283815678b5f45f693 to your computer and use it in GitHub Desktop.
Save marcbacon/b6283815678b5f45f693 to your computer and use it in GitHub Desktop.
If a visitor is not logged into the WordPress site, send them directly to the login page. After they have logged in, redirect them back to the home page.
// Place in functions.php or in a plugin
function redirection() {
if ( ! is_user_logged_in() ) {
wp_redirect( '/wp-login.php?redirect_to=' . home_url() );
exit;
}
} // end function
add_action( 'get_header', 'redirection' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment