简体   繁体   English

在WordPress中将白名单首页

[英]Whitelist home page in wordpress

I am using force login wordpress plugin to restrict user to login before viewing certain pages but i want to view home page without login i am trying to add home page in whitelist but its not working i am using my custom theme.Can you suggest what plugin should i use/what should i do for this purpose. 我正在使用强制登录wordpress插件来限制用户在查看某些页面之前登录,但是我想在不登录的情况下查看主页我试图在白名单中添加主页,但它不起作用,我正在使用我的自定义主题。我应该为此目的使用/应该做什么。

function my_forcelogin_whitelist( $whitelist ) {
            //$whitelist[] = 'http://localhost/wordpress/index.php/home/';
            //$whitelist[] = site_url( '/index.php/home/' );
              $whitelist[] = 'http://localhost/wordpress/index.php/';
              $whitelist[] = site_url( '/index.php/' );

        return $whitelist;
    }
    add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);

Insert this code to your theme's functions.php. 将此代码插入主题的functions.php中。 It will check if you're logged in or not. 它将检查您是否已登录。 For next, if current page is not homepage or frontpage, it will redirect user to login page. 接下来,如果当前页面不是主页或首页,它将把用户重定向到登录页面。

And you don't need other plugin to redirect, so please disable any force login plugin before test this code. 而且您不需要其他插件来重定向,因此请在测试此代码之前禁用任何强制登录插件。

function logged_in_only() {
    if ( ! is_user_logged_in() ) {
        if( !is_home() || !is_front_page() )
            auth_redirect();
    }
}
add_action( 'template_redirect', 'logged_in_only' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM