auth_redirect() or wp_redirect() from a specific page in wor


auth_redirect() or wp_redirect() from a specific page in wordpress

当用户点击页面的某个菜单项时,我想重定向用户登录。只有该项目需要登录,然后重定向回页面。所有其他页面都已打开供公众查看。我搜索了很多关于如何对特定页面使用auth_redirect()的信息,但都没有用。请帮忙。

这可以完成任务。。只要照顾好条件,我就把两者都放了,去掉了不需要的。。

function my_page_template_redirect()
{
    if( is_page( 'your-page-slug' ) || is_singular('your-post-type' ) /** just removed not need condition if its a page keep page and if its a post keep singular one **/
    {
        if(!is_user_logged_in())
        {
            auth_redirect();
        }
    }
}
add_action( 'template_redirect', 'my_page_template_redirect' );