0

I need to redirect users not logged in to any page I choose. Not the login page. I tried placing this code in the header, but it is an endless loop. Anybody know what code I need? Thanks

<?php if (!is_user_logged_in()) { wp_redirect( 'http://skeeterz71.com/cyber/about/'); exit; } ?> 
1

2 Answers 2

1

You can do it by adding some code in functions.php file

function user_redirect() { // Current Page global $currentpage; // Check to see if user in not logged in and not on the login page if(!is_user_logged_in() && $currentpage!= 'wp-login.php') // If user is, Redirect to Login form. wp_redirect( 'http://skeeterz71.com/cyber/about/'); } // add the block of code above to the WordPress template add_action( 'wp', 'user_redirect' ); 
Sign up to request clarification or add additional context in comments.

6 Comments

yes this will work. but what if he is trying to redirect on about us page also? as he says its going in endless loop.
I don't know what I am doing wrong. I added the code copy and paste into functions.php and still it is a continuous loop according to ff and chrome.
Do I add this to the header maybe? // add the block of code above to the WordPress template add_action( 'wp', 'user_redirect' );
Redirect loops can be caused by redirects in an .htaccess file or by redirection plugins. did you add any redirection plugin @user1951143
do a check for about us page as i have showed in my reply
|
0

If you have the same redirect code on about us page, you can put a check like below

<?php if (!is_user_logged_in()) { if(!is_page('about')) wp_redirect( 'http://skeeterz71.com/cyber/about/'); exit; } ?> 

or, you can check for page template instead of is_page()

if(!is_page_template('page-about.php')) wp_redirect( 'http://skeeterz71.com/cyber/about/'); exit; 

3 Comments

Same problem. No plugins installed other than aksimet. This is a new install of wp.
Did u tried above code? this code u can try in header or u hook it wp
Yes I tried all these suggestions to no success. except the page template because I am not using a custom page template

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.