Redirect logged out users when they go to a specific page on your WordPress website


Use this code to Redirect logged out users when they go to a specific page on your WordPress website

Add this code to the functions.php file of your WordPress or add a plugin in the wp-content folder of ftp/file manager in cPanel.
//Redirect logged out users when they go to specific page
add_action( 'template_redirect', 'redirect_if_user_not_logged_in' );

function redirect_if_user_not_logged_in() {

if ( is_page('dashboard') && ! is_user_logged_in() ) { //example can be is_page(23) where 23 is page ID

wp_redirect( 'https://mybusiness.702pros.com/signin ');

exit;// never forget this exit since its very important for the wp_redirect() to have the exit / die

}

}​

Did you find this article useful?