如果用户未登录并且要访问特定页面,则重定向到登录页面

问题描述 投票:0回答:1

如果用户尚未登录,并且想要访问以下页面(博客,事件,指导论坛,工作机会,实习机会和志愿者),我想将用户重定向到Wordpress中的登录页面。当前,重定向功能可以在博客和事件页面上正常使用。

这是功能代码:

add_action( 'template_redirect', function() {


    if ( ! is_page('login-to-view')  &&  ! is_user_logged_in() && ! is_page('/about-us') && ! is_page('/contacts') && ! is_page('') && ! is_page('/services')){
        auth_redirect();

    }

 });
php wordpress custom-wordpress-pages
1个回答
0
投票
if ( ! is_user_logged_in() && is_page( array( 'First page', 'Seconde page', 'Another page' ) ) ) {
    auth_redirect();
}

请不要忘记使用页面ID,标题或标题。

© www.soinside.com 2019 - 2024. All rights reserved.