Skip to content

Instantly share code, notes, and snippets.

@mattonomics
Last active December 12, 2015 12:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save mattonomics/4773955 to your computer and use it in GitHub Desktop.
Save mattonomics/4773955 to your computer and use it in GitHub Desktop.
This will make sure that only logged in users can view ANY content on the site. Drop it at the tip top of your functions.php file.
<?php
// fancy PHP 5.3+ style
add_action( 'template_redirect', function() {
if ( ! is_user_logged_in() ) {
wp_redirect( wp_login_url() );
exit;
}
} );
// and <PHP 5.3 style
if ( ! is_user_logged_in() && 'wp-login.php' !== $pagenow ) {
wp_redirect( wp_login_url() );
exit;
}
@mattonomics
Copy link
Author

props to @nacin and @nathanrice for the edits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment