Redirect all pages to wp-login.php
-
I would like to redirect all the pages to /wp-login.php except the login page, register page and activate/{activation-string}. I have a problem with the activate/{activation-string}, it goes to the wp-login.php, it should not redirect there.
Sample activation link after registration:
https://mysite.com/activate/NqAFdBGuET5WqTSS7zqlkL0DUyDYMOdF/ -> should not redirect to wp-login.phpThis is my current code
function not_logged_in_redirect() {
if (!is_user_logged_in()) {
if (!(is_page(‘login’) || is_page(‘register’)) && !(is_page() && preg_match(‘/^activate\/[a-zA-Z0-9]+$/’, get_query_var(‘activate’)))) {
wp_redirect(wp_login_url());
exit;
}
}
}
add_action(‘template_redirect’, ‘not_logged_in_redirect’);
- You must be logged in to reply to this topic.