I had a WordPress site requirement where only logged in users could see the site and it’s contents. I came across this bit of code a few years ago and found it to be helpful. Place it into your
functions.php and when a visitor comes along who is not logged in, it’ll redirect them to the
wp-login.php page to login. Once logged in, then they can view the site without being blocked.
This is an example where it can help keep unwanted visitors away from the content of your site.
It’s been working great and I wanted to share it.
Add the block below to make your website available to logged on authenticated users only. If a user is not authenticated, then they will be redirected to the login page
For more info, read http://obrienlabs.net/wordpress-logged-users-can-view-website/