Want to redirect non-logged in users to a specific page in WordPress? Use following code in your theme’s functions.php file OR in site specific plugin.
1 2 3 4 5 6 7 8 9 10 11 |
add_action( 'admin_init', 'fwm_redirect_non_logged_users_to_specific_page' ); function fwm_redirect_non_logged_users_to_specific_page() { if ( !is_user_logged_in() && is_page('add page slug or ID here') && $_SERVER['PHP_SELF'] != '/wp-admin/admin-ajax.php' ) { wp_redirect( 'http://www.freewebmentor.dev/demos/' ); exit; } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.