Redirect all pages to a ‘Coming Soon’ Page in WordPress
Tento článek (nebo jeho část) je převzat z externího zdroje. Je tedy slušností jej uvést včetně případného autora.
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.
1 2 3 4 5 6 7 |
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.
1 2 3 4 5 6 7 |
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.
Napsat komentář