Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top