WordPress comes with a wide range of functioinalities. But there are certain situations where we can not simply go by the default functoinailities. Such an example will be “login protected pages”..
Creating “private pages” and “password protected pages” functionalities are already there. With private pages, it can only be accessible by users having superior roles. On the other hand with password protected pages, it asks user for entering password even if he is already logged in.
So to create “login protected pages”, following steps can be useful.
– Create a template page. At the top of the template page, add login check function to check whether user is already logged in or not. If not logged in, user gets redirected to login page. – Create a page/article and assign to this template. – When user lands on this page, he gets redirected to the login page if he has not yet logged in. We can use the url of this page as the value for “redirect_to” in query string on the login page. – We can get the value of “redirect_to” from the url and set it in a hidden field in the login form. So after user logs in, he gets redirected to the actual page which he intended to visit.
WordPress uses redirect_to value to redirect user to any predefined page after login.