Redirect to login page if user not logged in
-
I am working on wordpress site and i want to redirect visitor to login page if visitor not logged in but for some pages. I have used below code but it is not worked for me. Means After adding code in function.php file, when i hit some pages and groups pages then it not redirect to login page. Helped me where i am wrong in this code. Also i have created login page not using BP login or wp-login
function login_required() { if (!is_user_logged_in() ) { $restricted = array(6,13,552,12,121,491,534,23,233,24,234,74,117,419); // all your restricted pages if ( in_array(get_the_ID(), $restricted ) ) { wp_redirect(home_url()); exit(); } } } add_action( 'template_redirect', 'login_required');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Redirect to login page if user not logged in’ is closed to new replies.