Reputation: 55
I'm using the following code in functions.php to redirect users who are not logged in, excluding if you are in wp-login.php.
if(!is_user_logged_in() && $pagenow != 'wp-login.php') {
wp_redirect( 'http://signup.mysite.com', 302 );
}
However, I've installed a shopping cart plugin that uses a different login page and basically redirects mysite.com/wp-login.php to mysite.com/account/login.
Is there some code I can use to exclude url paths from redirecting, perhaps something to replace $pagenow != 'wp-login.php'
?
Upvotes: 5
Views: 35436
Reputation: 385
<?php
if (!is_user_logged_in()) {
?>
<style>
.lor1{ display:none;}
.lor1.kun{ display: block;}
.lor1.user_not_login{ display: block;}
</style>
<?php } ?>
ADD this code in header.php
Upvotes: 0
Reputation: 196
Open Functions.php...
Paste:
// Redirect users who arent logged in...
function login_redirect() {
// Current Page
global $pagenow;
// Check to see if user in not logged in and not on the login page
if(!is_user_logged_in() && $pagenow != 'wp-login.php')
// If user is, Redirect to Login form.
auth_redirect();
}
// add the block of code above to the WordPress template
add_action( 'wp', 'login_redirect' );
hope this helps :)
Upvotes: 12
Reputation: 121
How about this..
//
// Re-direct not-logged-in users to holding page
//
if(!is_user_logged_in() && curPageURL() != 'http://mysite.com/wp-login.php') {
wp_redirect( 'http://signup.mysite.com', 302 );
exit;
}
//
// Get current page URL
//
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
Upvotes: 12
Reputation: 2404
You could experiment with the WordPress is_page( 'login' )
or maybe is_page( 'account/login' )
conditionals.
Upvotes: 0