更新时间:2023-12-01 17:42:10
有很多不同的方法可以根据您的最终目标进行此操作(使用WP登录页面,自定义登录页面等). .您可以尝试将其添加到主题的functions.php文件中:
There are a lot of different ways to do this based on what your ultimate goal is (use WP login page, a custom login page, etc...). You can try adding this to your theme's functions.php file:
if ( ( is_single() || is_front_page() || is_page() || is_archive() || is_tax() )
&& ! is_page( 'login' ) && ! is_page('register') && ! is_user_logged_in() ) {
auth_redirect();
}
或者您可以使用插件强制登录
更新
从理论上讲,您可能只需要使用它,而没有进行测试...
Theoretically, you can probably just use this, just haven't tested...
if( ! is_page('login') && ! is_page('register') && ! is_user_logged_in() ) {
auth_redirect();
}