只要确定一下auth_redirect() 为用户在所需页面上执行(在打印任何内容之前)。
有很多方法可以做到这一点。您可以向函数中添加类似的内容。php
$pages_auth_check = [ 25, 40, 55 ]; // IDs of the pages to check.
$current_page = get_the_ID();
if ( in_array( $current_page, $pages_auth_check ) ) {
auth_redirect();
}
所以
auth_redirect() 将仅对具有指定ID的页面执行。