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 if the user is not logged in and the page is not the home page then redirect the user to the home page, if you want a different page to direct them to,  change the parameters as below.

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

So above the as long as the page is not ‘comingsoon’ the non-logged in user will be redirected to it.

Leave all Comment