如何将未登录的用户重定向到Wordpress上的“登录"页面? [英] How to redirect non logged in users to Login page on Wordpress?

查看:809
本文介绍了如何将未登录的用户重定向到Wordpress上的“登录"页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个被问过百万次的问题,但是我找不到一个适合现在的Wordpress版本和/或我的具体情况的答案.

I know this is a question asked million times but I can't find an answer that is either fitting the version of Wordpress now and/or my particular case.

我有一个安装了Buddypress的Wordpress网站.

I have a Wordpress website with Buddypress installed on it.

我想要那个: -未登录的用户只能看到页面wp-login.php -登录的用户可以访问整个网站

I want that : - Not logged in users can see only the page wp-login.php - Logged in users can access the whole website

我只是想不通,这是不可能的.我要么更改站点地址,要么分配页面,或者功能……任何时候都无法正常工作,无论是错误还是404页面错误等等……

I just can't figure it out, it is impossible. Either I change the site address or assign a page, or fuctions... Nothing works, all the time an error or a 404 page error etc...

基本上:您到达网站后,如果登录会员"页面,则没有登录= Wp-Login.php

Basically : you arrive on the website, you are not logged in = Wp-Login.php, if you are logged in page "members"

谢谢!

推荐答案

有很多不同的方法可以根据您的最终目标进行此操作(使用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(); 
}

这篇关于如何将未登录的用户重定向到Wordpress上的“登录"页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆