admin管理员组文章数量:1316004
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?
本文标签:
版权声明:本文标题:How to add a switch to admin area which enablesdisables crisis-mode: Redirect all traffic to certain page if switch is enabled 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741988787a2408843.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论