Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created August 13, 2014 15:02
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save strangerstudios/7bbf6b2b21a9a0518a44 to your computer and use it in GitHub Desktop.
Save strangerstudios/7bbf6b2b21a9a0518a44 to your computer and use it in GitHub Desktop.
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