Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created August 13, 2014 15:02
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Various options for redirecting to a "Coming Soon" page with WordPress.
/*
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