Thursday, 30 January 2014

How to redirect non-logged users requesting for a specific page to another page?

How can we tell you where to put it if you didn't tell us what and where you want to display it? Whole posts? Pages? Custom parts of pages? Sorry... I guess my crystal ball isn't quite working today.
Since you are, and I quote you: "a newbie to wordpress" you should rather learn, than to ask for direct answer.
As for where you should read the reference 1 link. This will tell you which file you need to put it in.
As for how to do it you should first read reference link 2 and 3.
Overall it should look something like this:


if ( is_user_logged_in() ) {
the_content
();
} else {
echo
'For members only';
}


Of course the above code needs to go into a loop. You can build it up as complex or as simple as you want. For example instead of simple text if not logged in you can display whole sign up form for example or - as I would suggest - a divided screen where user can log in (since user can have an account but forgot to sign in) or sign up (if he doesn't have one).

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More