简体   繁体   English

如何使我的 wp-login.php 成为主页?

[英]How can I make my wp-login.php the homepage?

I want to know how I can make my wp-login.php to run as the homepage in WordPress?我想知道如何让我的 wp-login.php 作为 WordPress 的主页运行? So if one types: http://www.example.com it automatically goes to ../wp-login.php因此,如果一种类型: http : //www.example.com它会自动转到 ../wp-login.php

And if the user is already logged in it will go to index.php?如果用户已经登录,它会转到 index.php 吗?

I've allready tried adding我已经尝试添加

if(isset($_COOKIE['logincookie'])){
    return true;
} else {
    header("Location: http://www.example.com/wp-login.php");
}

on top of index.php and it works, only when I try to fill in the username and password nothing happens.在 index.php 之上,它可以工作,只有当我尝试填写用户名和密码时,什么也没有发生。

In your functions.php , you can set WP to redirect all pages to wp-login.php :在您的functions.php ,您可以设置 WP 将所有页面重定向到wp-login.php

<?php
function password_protected() {
    if ( !is_user_logged_in() )
        auth_redirect();
}

add_action('login_head', 'rsd_link');
add_action('login_head', 'wlwmanifest_link');
add_action('template_redirect', 'password_protected');
add_action('do_feed', 'password_protected');
?>

Alternately, you can also use:或者,您也可以使用:

if ( ( is_single() || is_front_page() || is_page() ) 
   && !is_page('login') && !is_user_logged_in()){ 
    auth_redirect(); 
}

Functions功能

  • is_single() will return true if it's a single post.如果是单个帖子, is_single()将返回true

  • is_front_page() will return true if it's the homepage.如果是主页, is_front_page()将返回true

  • is_page() will return true if it's a single page.如果是单页, is_page()将返回true

  • is_page('login') will return true if it's the login page.如果是登录页面, is_page('login')将返回true

  • is_user_logged_in() will return true if the user is logged in already.如果用户已经登录, is_user_logged_in()将返回true

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

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