Various options for redirecting to a "Coming Soon" page with WordPress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
1. Create a page called "Coming Soon" with the slug "coming-soon". | |
If you use something different, be sure to update the code below. | |
2. Copy just one of the blocks of code below to a custom plugin or your active theme's functions.php. | |
*/ | |
//redirect non-users to the coming soon page | |
function coming_soon_redirect() | |
{ | |
global $pagenow; | |
if(!is_user_logged_in() && !is_page("login") && !is_page("coming-soon") && $page_now != "wp-login.php") | |
{ | |
wp_redirect(home_url("coming-soon")); | |
exit; | |
} | |
} | |
add_action('template_redirect', 'coming_soon_redirect'); | |
//redirect non-admins to the coming soon page | |
function coming_soon_redirect() | |
{ | |
global $pagenow; | |
if(!current_user_can('manage_options') && !is_page("login") && !is_page("coming-soon") && $page_now != "wp-login.php") | |
{ | |
wp_redirect(home_url("coming-soon")); | |
exit; | |
} | |
} | |
add_action('template_redirect', 'coming_soon_redirect'); | |
//redirect non-members (requires Paid Memberships Pro) to the coming soon page | |
function coming_soon_redirect() | |
{ | |
global $pagenow; | |
if(function_exists('pmpro_hasMembershipLevel') && !pmpro_hasMembershipLevel() && | |
!is_page("login") && !is_page("coming-soon") && $page_now != "wp-login.php") | |
{ | |
wp_redirect(home_url("coming-soon")); | |
exit; | |
} | |
} | |
add_action('template_redirect', 'coming_soon_redirect'); | |
//redirect non-users to coming soon page, but allow certain other pages | |
function coming_soon_redirect() | |
{ | |
global $pagenow; | |
$okay_pages = array("login", "coming-soon", "about", "contact", "faq"); | |
if(!is_user_logged_in() && !is_page($okay_pages) && $page_now != "wp-login.php") | |
{ | |
wp_redirect(home_url("coming-soon")); | |
exit; | |
} | |
} | |
add_action('template_redirect', 'coming_soon_redirect'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment