In this article I will explain you how to make your WordPress private only to registered users.


  1. Open file  functions.php

  2. Copy and paste the following code:

function private_wp() {
if (!is_user_logged_in()) {
add_action('get_header', 'private_wp');

When this code is called from a page, it checks to see if the user viewing the page is logged in. If the user is not logged in, they are redirected to the login page. The user is redirected in such a way that, upon logging in, they will be sent directly to the page they were originally trying to access.