Case: There is natural disaster or terrorist attack etc. Admin logins to site and enables "crisis mode". All traffic gets redirected to crisis page.
I found this code from another answer which deals the redirect part. So how to create a switch to admin area which executes the code.
add_action( 'template_redirect', function() {
if ( is_page( 813 ) ) {
return;
}
wp_redirect( esc_url_raw( home_url( 'index.php?page_id=183' ) ) );
exit;
} );
Answer to the question: I fiqured out a solution with ACF option field.
- Create option page
- Add 1/0 Switch to option page
- Add code to child themes functions.php
add_action( 'template_redirect', function() {
if ( is_page( 853 ) ) {
return;
}
if(get_field('crisis', 'option')) {
wp_redirect( esc_url_raw( home_url( 'index.php?page_id=853' ) ) );
exit;
}
} );
- Done.
Do you have a better approuch to this?