Redirect all pages to a ‘Coming Soon’ Page in WordPress

You can redirect all your WordPress pages to a designated Coming Soon page for all non-logged in users with the template_redirect action hook whilst leaving all pages visible to logged in users.

add_action( 'template_redirect', 'themeprefix_coming_soon' );
function themeprefix_coming_soon() {
	if( !is_user_logged_in() && ! is_front_page() || is_home() ){
		 wp_redirect( site_url() );
		 exit();
	}
}

So in the above code snippet if the user is not logged in the user will be redirected the user to the home page, if you want a different page to redirect the logged out user to,  change the parameters as below.

add_action( 'template_redirect', 'themeprefix_coming_soon' );
function themeprefix_coming_soon() {
if( !is_user_logged_in() && !is_page('coming-soon') ){
wp_redirect( site_url('coming-soon') );
exit();
}
}

So in the code snippet above, the logged out user will be redirected to the ‘coming-soon’ page.

Leave all Comment