Is it possible to restrict WordPress index page to logged in users?

I’d like to make all my articles publicly accessible but in order to view the index page, a user must first register with the site. Is this possible?

Related posts

Leave a Reply

1 comment

  1. To implement in a particular page you can use the following:

    To limit the access to one particular page (or some pages) so that only logged in users can reach it, I make a new page template for that purpose and then I put this bit of code in the beginning of the template (right after the ):

    <?php if ( !is_user_logged_in() ) {
    nocache_headers();
    header("HTTP/1.1 302 Moved Temporarily");
    header('Location: ' . get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode($_SERVER['REQUEST_URI']));
    header("Status: 302 Moved Temporarily");
    exit();
    }
    ?>
    

    the above example is taken from here

    Additionally, you can use any one of the several wordpress plugins out there. One example is here. I have used this plugin before and it works pretty well. There are other similar plugins with varying features. A simple google search would give you lots of options.