Require Login to View the Site
Makes the whole front end private: visitors who are not logged in are sent to the login page and returned to the page they asked for afterwards.
Opens WPIDE on
Code
add_action( 'template_redirect', function () {
if ( is_user_logged_in() ) {
return;
}
// Page slugs that stay public, for example array( 'contact', 'privacy-policy' ).
$public_pages = array();
if ( $public_pages && is_page( $public_pages ) ) {
return;
}
auth_redirect();
} );
Notes
Feeds and the REST API are not covered. Combine with "Restrict the REST API to Logged-In Users" for full privacy.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.